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

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

Open
Tolga1452 opened this issue Jan 25, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Tolga1452
Copy link

Tolga1452 commented Jan 25, 2025

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();
};
@Tolga1452 Tolga1452 added the bug Something isn't working label Jan 25, 2025
@Tolga1452
Copy link
Author

Tolga1452 commented Jan 25, 2025

Update

experimental_attachments for append() works if you use it in request options, like:

append(
  {
    role: 'user',
    content: 'What do you see in this image?'
  },
  {
    experimental_attachments: files
  }
);

The first method doesn't work in the message object in my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant