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

data part is not appended to message #4213

Closed
JerryKwan opened this issue Dec 27, 2024 · 5 comments
Closed

data part is not appended to message #4213

JerryKwan opened this issue Dec 27, 2024 · 5 comments
Labels

Comments

@JerryKwan
Copy link

JerryKwan commented Dec 27, 2024

Description

When using DataStreamWriter's writeData() to send custom data, the data part is not assigned the message as the operations when invoking writeMessageAnnotation() which annotations are assigned to message as expected.
In the current implementation the data is cached and returned as data for the whole chat, not accessible by message, although Message has a data field, but it's never assigned.
As you can see from the following code snippets.

https://github.com/vercel/ai/blob/main/packages/ui-utils/src/process-chat-response.ts#L222-L234
https://github.com/vercel/ai/blob/main/packages/ui-utils/src/types.ts#L47-L82

It would be better the data part is accessible by message like annotations.

Code example

No response

AI provider

No response

Additional context

No response

@JerryKwan JerryKwan added the bug Something isn't working label Dec 27, 2024
@lgrammel lgrammel added the ai/ui label Jan 6, 2025
@ifreeman6
Copy link

ifreeman6 commented Jan 17, 2025

I meet the same issue. Any solutions about it ?

@JerryKwan
Copy link
Author

@ifreeman6
I think it just need a little hack of the process-chat-response.ts if you maintain your own fork.

@lgrammel
Copy link
Collaborator

data is per chat, messageAnnotations are per message. Please use messageAnnotations for your use case if you need data per message.

@lgrammel lgrammel removed the bug Something isn't working label Jan 17, 2025
@JerryKwan
Copy link
Author

@lgrammel
Thanks for paying attention to this issue.
As far as I know, messageAnnotations is not per message all of the time.
Consider the following scenario,
When a FinishStepPart was sent, and several messages should be returned right? but how messageAnnotations are processed? messageAnnotations are not cleared when a new message starts, they are accumulated. and the last message has all of the annotations.

@lgrammel
Copy link
Collaborator

On the client you need to accumulate consecutive assistant messages manually (unfortunately). It is related to mapping the messages back to the LLM format. When you do this accumulation, you would also get annotations from both msgs. I'll write this up somewhere, it is a somewhat annoying limitation that I plan to overcome with a new approach to AI SDK UI.

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

No branches or pull requests

3 participants