Add support for callbacks on streamed response #322
Labels
component:js sdk
Issue/PR related to JavaScript SDK
status:triaged
Issue/PR triaged to the corresponding sub-team
type:feature request
New feature request/enhancement
Description of the feature request:
Add callbacks on streamed response to allow developers to easily manage generating streamed chat responses with callbacks such as saving the prompt to database or any server side call.
What problem are you trying to solve with this feature?
This feature is helpful for a good DX. Currently the user will need to manage the response manually. For example I had to implement this function to get a streamed response with callbacks:
What this function does is allowing the user to sign a
onData
andonEnd
functions. The server will then callonData
on every chunk received from the LLM API andonEnd
is called at the end of the generation of the response. This way, It provides the user with a chat-like streamed response without the need to way for the entire response. It also allows the developer to save the response on the end of the generation without relying on any client-side callback.It would be a good idea to expose the developer with a function like this:
The returned response is
Response
which would allow for directly returning the value in frameworks like Next.js and SvelteKitAny other information you'd like to share?
This could also be beneficial in Express.js and Hono.
I am ready to implement it and file a PR.
The text was updated successfully, but these errors were encountered: