-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selecting any of the trending memecoins throws Cannot destructure property 'role' error
#325
Comments
the messages sent to openai are not formatted properly. Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'. I was testing. This works. const toolCallMessage: CoreMessage = {
role: "assistant",
content: [
{
type: "tool-call",
toolName: "showStockPurchase",
toolCallId: "8Bb6oJ1vAIRuHSIAVYmAp",
args: z.object({
symbol: z.string(),
price: z.number(),
defaultAmount: z.number(),
}),
},
],
};
const toolMessage: CoreMessage = {
role: "tool",
content: [
{
result: JSON.stringify({
symbol: "AAPL",
price: 150,
defaultAmount: 100,
status: "completed",
}),
type: "tool-result",
toolCallId: "8Bb6oJ1vAIRuHSIAVYmAp",
toolName: "showStockPurchase",
},
],
};
const all = [...messages, toolCallMessage, toolMessage]; |
@prashantbhudwal Could you raise a PR please? |
@athrael-soju |
Same error. Any solution? |
Because the new SDK uses streamUI ai-chatbot/lib/chat/actions.tsx Line 140 in 095550d
And old one uses a render ai-chatbot/lib/chat/actions.tsx Line 144 in d5f7361
|
The bug appears when using streamUI, not render. If you revert to the previous commit it works fine with render. |
I have the same error after clicking on the first generated component, I update everything even nextjs but it didn't work |
Yes, this is an issue with the new code. I guess it should be reverted or fixed? I tried a few things to resolve it, but wasn't able to. |
The latest update "streamUI instead of render #324" does not allow messages with "role: system" between conversation (only at start) with new prompt param system. The "problem" is: The error This function is inside of dependency "ai": "^3.1.1"
I tested in compiled module inside
This works but the correction must be made in the repository of the dependency "ai": "^3.1.1". And this depends on whether it is considered good practice to send system messages inside of the conversation to save new context (user events) |
@kevb10 you can track your messages in the function streamUI locate in Check messages before and after And you can do testing with the function P.S. remember that you are in the dependency |
Thanks @kevb10. It didn't solve my problem either, but it's nice to see progress on this issue Update: I implemented your sanity check and it works for me. |
@kevb10's sanity check also works for me, using patch-package to create a patch file instead of making edits inside of Just ran Followed by: And the issue went away. Still interested in a more permanent solution, though. |
Can anyone please explain why https://chat.vercel.ai/ works perfectly fine, but the main branch on localhost does not? Isn't the main branch from the repo deployed to this domain? |
Maybe because that might point to some old commit. |
Just noting that I'm also running into this bug and have been troubleshooting it a bit today. This affects any component that makes use of function or system role messages and happens after an unsupported message role type has been inserted into the chat history (which creates an undefined chat message). What I've found mirrors what some of the other commenters have noted: adjusting the node_modules/ai/rsc/dist/rsc-server.msj file's convertToLanguageModelPrompt() function to handle more of the message types defined in actions.tsx (specifically 'function' and 'system') seems to eliminate the error, although it's not a good solution since it's a workaround in the dependency and I'm not clear what other effects that change might be having. Something in the RSC framework is choking on handling message types of 'function', 'tool', 'data', and in some cases 'system' and it's causing them to become undefined messages in the chat history array, which is creating downstream problems elsewhere in the app. I'm also not clear on whether those roles are intended to be functional in the RSC or with GPT-4 and just aren't working here yet, or if the app is trying to do something it shouldn't be and using the roles incorrectly. The message role functionality is still very new to me! |
Replacing all function roles to assistant works. And now ai SDK version [email protected] has support for system message https://github.com/vercel/ai/blob/main/packages/core/core/prompt/message.ts#L12 |
Honestly, with all the bugs combined, you're better off using the vercel-ai-src example |
Thanks everyone for trying to debug the issue and I appreciate everyone's patience! Like you all had suspected, the #337 follows the messages spec and should fix the error! I will also have an upgrade guide up in the docs soon to provide more clarity about this change and prevent any future confusion. |
@jeremyphilemon although #324 resolves the majority of issues from using streamUI over render, this one still remains.
Simply get the trending memecoins to show and select one of them. Error attached.
The text was updated successfully, but these errors were encountered: