-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Description
When sending messages of { type: 'file', mediaType: 'text/plain', data: '....string of base 64 encoded data...' } using generateText or streamText, the base 64 encoded string is passed verbatim to the OpenAI Compatible API, inside a {"type":"text","text":"...base 64 encoded data..."} message. Passing the data as base64 is correct when the message to the server is inside a type: 'file' message, but is incorrect when the message to the server is type: 'text'
This contradicts the documentation, which indicates that the data field in FilePart messages is supposed to be a base64 encoded string, as seen here:
https://ai-sdk.dev/docs/reference/ai-sdk-core/generate-text#messages.user-model-message.content.file-part
The incorrect code is on line 122 of this file:
https://github.com/vercel/ai/blob/ed17fe86d13bed87a21dc0264178bd2417f999ce/packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts
The textContent should be Base64 decoded when using type: 'text' messages
AI SDK Version
Latest Git
Code of Conduct
- I agree to follow this project's Code of Conduct