ai icon indicating copy to clipboard operation
ai copied to clipboard

[feature] provide a callback to useChat for when messages are completed

Open dilanustek opened this issue 2 years ago • 2 comments

The useChat hook has an onFinish callback which fires when everything is completed. With the new experimental feature to stream additional data, the onFinish callback fires not after the tokens are completed but after any data is also done loading.

We need to be able to tell when the messages are completed so that we can show a loading state for the additional data that is being calculated based off of the message received. It would be nice to have an onCompleted callback added to the useChat hook on the client side. It may also look like a isMessageLoading added to the isLoading boolean to indicate the difference.

dilanustek avatar Aug 23 '23 18:08 dilanustek

I support an onCompletion to closer align the client API and server API. PR's welcome!

MaxLeiter avatar Aug 24 '23 18:08 MaxLeiter

Great suggestion @dilanustek. I've started a draft PR for this here: https://github.com/vercel/ai/pull/554

ctate avatar Sep 13 '23 07:09 ctate

in ai sdk the finish hook is invoked when the response is complete

lgrammel avatar Jun 26 '25 08:06 lgrammel