-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
AI_InvalidPromptError: Invalid prompt: messages must be an array of CoreMessage or UIMessage #5499
Comments
so should fix the type definition of |
@HomyeeKing could you help me understand where you're getting the assistant message you're passing to in the code snippet you shared there are some type discrepancies:
|
@iteratetograceness const { messages, setMessages } = useChat({
// ....
})
const { response } = await generateText({
model: openai('gpt-4o'),
messages: messages
});
// setMessages fills every type of message with `part` property
// so it will mismatch the
// Array<CoreSystemMessage | CoreUserMessage | CoreAssistantMessage | CoreToolMessage> | Array<UIMessage>
setMessages(...response.messages) then I use // ...
const { response } = await generateText({
// ...
messages: convertToCoreMessages(messages)
});
// .... then the |
In my case, this part seems to produce an illegal core message payload. before
after
|
@HomyeeKing ah, so a couple of issues here! First, you're attempting to pass the Secondly, what's your use case for using |
@longfin your before payload itself appears to be invalid, it's a mesh of both |
|
@HomyeeKing I recommend using the boilerplate code—it's quite quick to get things set up even while you're building out chat UI! You could even hook it up, copy the initial array of messages returned and use as mock data. But if you prefer to stick to your approach your issue should be resolved as long as you convert the messages returned from Will close this issue unless @longfin has a similar but different concern! |
My payload was created by
Agree, I'll open a new issue having more detailed context soon. |
@iteratetograceness but I still have one question: const [] = useChat({
model: xxx,
tools: xxx
}) I think it's one common way(I don't have specific statistics) for developers to use it that way and the current one needs to define tools on server-side which might spends extra time to implement, not firendly to make a quick app |
@HomyeeKing client-side tools are supported with useChat! See this docs page: https://sdk.vercel.ai/docs/ai-sdk-ui/chatbot-tool-usage |
Description
After upgrade the ai-sdks to the latest, the exact version are list below, can't get pass the zod validation.
part
property https://github.com/vercel/ai/blob/main/packages/react/src/use-chat.ts#L465part
property failed the zod validation, so I useconvertToCoreMessages
this util to remove it, unfortunately still can't pass the validationpart
of the user message was removed, but theassistant
message is formatted to mismatch theCoreAssistantMessage
Code example
AI provider
"@ai-sdk/provider": "^1.1.0",
Additional context
The text was updated successfully, but these errors were encountered: