Skip to content

React useChat(): experimental_attachments doesn't work for reload() and append() #4519

Closed
@Tolga1452

Description

@Tolga1452

Description

When using useChat() for ai/react with @ai-sdk/openai, experimental_attachments only works with handleSubmit().

reload() and append() don't handle the attachments given via experimental_attachments.

Code example

import { useChat } from 'ai/react';

const { handleSubmit, append, reload } = useChat();

// ...

handleSubmit(event, {
  experimental_attachments: files
}); // Works as expected

// ...

reload({
  experimental_attachments: files
});  // Doesn't add attachments to the message

// ...

append({
  role: 'user',
  content: 'What do you see in this image?',
  experimental_attachments: files
}); // Adds the message without attachments

AI provider

@ai-sdk/openai v1.1.2

Additional context

The package version is up-to-date: v4.1.5

I use the following code for handling requests:

import { openai } from '@ai-sdk/openai';
import { streamText, tool } from 'ai';
import z from 'zod';

export const maxDuration = 30;

export async function POST(req: Request) {
    const { messages } = await req.json();

    const result = streamText({
        model: openai('gpt-4o'),
        messages,
        tools: { /* ... */ },
        experimental_toolCallStreaming: true
    });

    return result.toDataStreamResponse();
};

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