Skip to content

AI_InvalidPromptError: Invalid prompt: messages must be an array of CoreMessage or UIMessage #5499

@HomyeeKing

Description

@HomyeeKing

Description

After upgrade the ai-sdks to the latest, the exact version are list below, can't get pass the zod validation.

  1. setMessages modify the original message object and fill the part property https://github.com/vercel/ai/blob/main/packages/react/src/use-chat.ts#L465
  2. I thought the new part property failed the zod validation, so I use convertToCoreMessages this util to remove it, unfortunately still can't pass the validation
  3. the part of the user message was removed, but the assistant message is formatted to mismatch the CoreAssistantMessage

Code example

import { convertToCoreMessages } from 'ai';

const res = convertToCoreMessages([
  {
    role: 'assistant',
    content: [
      {
        type: 'text',
        text: 'xxxxxxxxx',
      },
    ],
    parts: [
      {
        type: 'text',
        text: [
          {
            type: 'text',
            text: 'xxxxxxxxxxx',
          },
        ],
      },
    ],
  },
]);

console.log('res', res);

AI provider

"@ai-sdk/provider": "^1.1.0",

Additional context

"@ai-sdk/openai": "^1.3.6",
  "@ai-sdk/openai-compatible": "^0.2.4",
  "@ai-sdk/provider": "^1.1.0",
  "@ai-sdk/provider-utils": "^2.2.3",
  "@ai-sdk/react": "^1.2.5",
  "ai": "^4.2.10"

Metadata

Metadata

Labels

ai/corecore functions like generateText, streamText, etc. Provider utils, and provider spec.ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelbugSomething isn't working as documentedprovider/openaiIssues related to the @ai-sdk/openai providerprovider/openai-compatibleIssues related to the @ai-sdk/openai-compatible provider

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions