-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support both callback and generator-based streaming in all Chat Generators #8742
Comments
This article by @aryaminus covers the workarounds and mental gymnastics users have to go through to enable this functionality. |
@vblagoje yeah I saw it. In general I agree with proposed approach, my points:
I think we need first to investigate which is the primary use case for
On SSE use case (ie open-webui), network timeout errors (the most common ones) should be handled on the client side. If one instead simply consume a generator, error should be handled while consuming it with classic try / except block.
I agree on this! |
@vblagoje felt like dropping my thoughts:
my leniency is towards Option 1 (Component Socket Detection) for seamless integration but suggest adding an optional parameter (e.g., |
Thanks @aryaminus - very good suggestion on |
Motivation
Currently, all chat generator components (OpenAI, Anthropic, etc.) support streaming only through callbacks:
This works well for simple use cases (notebooks etc), but becomes problematic when:
Integrating with async frameworks like FastAPI that expect a generator for streaming responses:
Building pipelines where downstream components expect to consume a stream of tokens:
Implementing custom streaming logic that doesn't fit the callback pattern:
Proposed Solution
Add a second output socket
stream
to all chat generator components:This allows components to support both streaming patterns:
Callback-based (existing behavior):
Generator-based (new behavior):
Implementation Details
Two possible approaches:
Option 1: Use Component Socket Detection
Add helper method to detect if stream socket is connected:
Components would enable streaming based on either callback or socket connection:
Pros:
Cons:
Option 2: Use Sentinel Value
Add sentinel to signal generator-based streaming:
Pros:
Cons:
Questions to Resolve
The text was updated successfully, but these errors were encountered: