Skip to content
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

DOMException [InvalidCharacterError]: Invalid character #1505

Closed
bernaferrari opened this issue May 6, 2024 · 2 comments
Closed

DOMException [InvalidCharacterError]: Invalid character #1505

bernaferrari opened this issue May 6, 2024 · 2 comments
Assignees

Comments

@bernaferrari
Copy link

bernaferrari commented May 6, 2024

Description

Just sending a simple PNG to GPT I'm getting this:

    const stream = await streamObject({
      model: openai.chat("gpt-4-turbo"),
      schema: z.object({
        children: z.array(z.object({})),
      }),
      system: `Do this`,
      messages: [formatVercelUserMessage(userMessage, base64Image)],
    });


export const formatVercelUserMessage = (
  message: string,
  base64Image?: string | null
): CoreUserMessage => {
  if (base64Image) {
    return {
      role: "user",
      content: [
        { type: "text", text: message },
        {
          type: "image",
          image: base64Image,
        },
      ],
    };
  }

  return {
    role: "user",
    content: message,
  };
};
 ⨯ unhandledRejection: DOMException [InvalidCharacterError]: Invalid character
    at atob (node:buffer:1269:13)
    at convertBase64ToUint8Array (webpack-internal:///(action-browser)/../node_modules/.pnpm/@ai-sdk+provider-utils@0.0.5_zod@3.23.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs:396:35)
    at convertDataContentToUint8Array (webpack-internal:///(action-browser)/../node_modules/.pnpm/ai@3.1.1_react@18.3.1_solid-js@1.8.7_svelte@4.2.8_vue@3.3.13_typescript@5.4.5__zod@3.23.6/node_modules/ai/dist/index.mjs:121:93)
    at eval (webpack-internal:///(action-browser)/../node_modules/.pnpm/ai@3.1.1_react@18.3.1_solid-js@1.8.7_svelte@4.2.8_vue@3.3.13_typescript@5.4.5__zod@3.23.6/node_modules/ai/dist/index.mjs:171:44)
    at Array.map (<anonymous>)
    at eval (webpack-internal:///(action-browser)/../node_modules/.pnpm/ai@3.1.1_react@18.3.1_solid-js@1.8.7_svelte@4.2.8_vue@3.3.13_typescript@5.4.5__zod@3.23.6/node_modules/ai/dist/index.mjs:156:42)
    at Array.map (<anonymous>)
    at convertToLanguageModelPrompt (webpack-internal:///(action-browser)/../node_modules/.pnpm/ai@3.1.1_react@18.3.1_solid-js@1.8.7_svelte@4.2.8_vue@3.3.13_typescript@5.4.5__zod@3.23.6/node_modules/ai/dist/index.mjs:145:28)
    at streamObject (webpack-internal:///(action-browser)/../node_modules/.pnpm/ai@3.1.1_react@18.3.1_solid-js@1.8.7_svelte@4.2.8_vue@3.3.13_typescript@5.4.5__zod@3.23.6/node_modules/ai/dist/index.mjs:1053:17)
    at eval (webpack-internal:///(action-browser)/./app/playground/actions.tsx:64:79)

Example image being sent:
image

@lgrammel
Copy link
Collaborator

#1569

@lgrammel
Copy link
Collaborator

string data urls are support with 3.1.35+: https://sdk.vercel.ai/docs/ai-sdk-core/prompts#multi-modal-messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants