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

Pass 'data' attribute to endpoint on react/use-chat #1389

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-students-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Pass 'data' attribute on react/use-chat
11 changes: 10 additions & 1 deletion packages/core/react/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,20 @@
const constructedMessagesPayload = sendExtraMessageFields
? chatRequest.messages
: chatRequest.messages.map(
({ role, content, name, function_call, tool_calls, tool_call_id }) => ({
({
role,
content,
data,
name,
function_call,
tool_calls,
tool_call_id,
}) => ({
role,
content,
tool_call_id,
...(name !== undefined && { name }),
...(data !== undefined && { data }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to pass this on for messages, we'd need this to change in Svelte, Solid and Vue useChat as well.

...(function_call !== undefined && {
function_call: function_call,
}),
Expand Down Expand Up @@ -325,7 +334,7 @@
mutateLoading(false);
}
},
[

Check warning on line 337 in packages/core/react/use-chat.ts

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useCallback has a missing dependency: 'streamMode'. Either include it or remove the dependency array
mutate,
mutateLoading,
api,
Expand Down