ai
ai copied to clipboard
Proposing `onAppend` callback method for `useChat` hook
Feature Description
I propose adding an onAppend
callback function to the useChatOptions
. This callback would be invoked whenever a user message is appended to the chat list using the append
function, triggering the API call to fetch the assistant's response.
type UseChatOptions = {
// ...
onAppend?: (message: Message | CreateMessage) => void;
// ...
};
Use Case
The onAppend callback would be useful for enhancing the interactivity and responsiveness of the chat UI. By implementing the onAppend callback, developers can provide visual feedback or trigger animations when a user message is appended to the chat list, indicating that the assistant is processing the message and generating a response (e.g. "typing" indicator or animation).
Additional context
The onAppend callback would be invoked immediately after a user message is appended to the chat list using the append
function, but before the API call is made to fetch the assistant's response.