ai
ai copied to clipboard
Passing parameter to useChat > reload() function with Server Action is not working
Description
- Create a useChat with the api as a server action (for experimental_StreamingReactResponse),
- The api as a server action worked fine.
- pass a parameter to reload (for re-generating)
- this parameter is not passed as a parameter to the handler
Code example
### Front-end
const { messages, input, reload, handleInputChange, handleSubmit } = useChat({
api: handler,
});
const handleRegenerate = () => {
reload({
options: {
body: {
isRegenerate: true,
},
},
});
};
### Server Action
"use server";
export async function handler(req: any) {
console.log("Request", req);
}
### Output Request { messages: [ { role: 'user', content: 'Hi' } ] }
(There is no way to get the isRegenerate parameter passed from client)
Additional context
No response
I am also reporting attempts to pass any ChatRequestOptions to reload(), for example:
options = {
data: {
key1: value1;
key2: value2
}
}
reload(options)
The route.ts of useChat does not receive the options, just the messages.
Hope you can prioritize this requirement. Cheers RS
@leotrieu @robertoshimizu have any of you found a fix for this yet?
I have solved this problem by this
const options = { api: "/api/chat?id=hello", }; const { messages, input, handleInputChange, handleSubmit } = useChat(options);
I can't find anywhere in the doc where it says you can put a server action into useChat()
's api
parameter. Instead, it says the api
parameter takes a string
value.
Although it'd be nice if we could 😁
https://github.com/vercel/ai/blob/5063b8cb2b481d95b00c022566c16e63489c68c9/packages/ui-utils/src/types.ts#L283 https://github.com/vercel/ai/blob/5063b8cb2b481d95b00c022566c16e63489c68c9/packages/ui-utils/src/call-chat-api.ts
Yep, confirmed. All type definitions of api
expects a string.
Are there any updates on useChat's reload and why it's dropping passed ChatRequestOptions?