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

Allow to call a callback on streaming responses #310

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

unsync
Copy link

@unsync unsync commented Apr 22, 2024

Title: Allow to call a callback on streaming responses

Description: (optional)
This PR allows to call a user-defined function (null-safe) with the stream content (list of chunks)

Motivation: (optional)
The motivation behind this is that i run a fork of the gateway (i needed to introduce a custom middleware) and to add tracing for the stream responses, i have a working solution (transform the stream without actually changing the format, only adding the same logic i added in this PR) but having this as a native feature of the gateway would improve the overall implementation.

The idea is actually similar to what is done with the getFromCache function.

This is a first (working) proof-of-concept, if the idea of this feature is accepted, i'm more than ready to improve the implementation if needed.
Regarding the impact on performance, i think that if the function is not set the impact is non-existant, and if the function is set, then the performance has to be accepted by those implementing the function.

If accepted, it could also be a first step to have some level of callbacks/hooks for those running forks to extends the open-source gateway.

@unsync unsync force-pushed the feat/use-stream-callback branch 2 times, most recently from e069641 to eb2542b Compare April 26, 2024 06:02
@unsync unsync force-pushed the feat/use-stream-callback branch 2 times, most recently from 4f624ee to 3df26ed Compare May 23, 2024 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant