Skip to content

useChat setMessages Assertion #1106

Closed
Closed
@jongreen96

Description

@jongreen96

Description

useChat's chat helper setMessages errors when setting a messages content to anything other than a string.

Error: Assertion: Unexpected value [object Object] for children prop, expected string

This is incorrect behavior as OpenAI's API accepts a string or array when working with their vision models, I have included a example below.

messages: [
      {
        role: "user",
        content: [
          { type: "text", text: "What’s in this image?" },
          {
            type: "image_url",
            image_url:
              "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
          },
        ],
      },
    ],

Code example

setMessages([
    ...messages,
        {
            role: 'user',
            content: [
                 { type: 'text', text: input },
                 {
                     type: 'image_url',
                     image_url: { url: images[0], detail: 'low' },
                 },
           ],
       },
]);

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/uibugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions