-
Notifications
You must be signed in to change notification settings - Fork 351
Fix Ollama client streaming issue with stream=True #439
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,17 +364,29 @@ def _post_call(self, completion: Any) -> GeneratorOutput: | |
# Now adding the data field to the output | ||
data = output.raw_response | ||
|
||
# TODO implement support for synchronous iterator in the future | ||
if self.output_processors: | ||
if data: | ||
try: | ||
data = self.output_processors(data) | ||
output.data = data | ||
except Exception as e: | ||
log.error(f"Error processing the output processors: {e}") | ||
output.error = str(e) | ||
# Check if this is a streaming response (generator/iterator) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this pr does not do much. and we cant force the data to None either. It is supposed to be the final complete output data, which should be handled in ollama_client, where u have to collect all stream and save the complete one in this field. you can see example in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep the generator not changed at all |
||
from typing import Generator as GeneratorType | ||
from collections.abc import AsyncGenerator as AsyncGeneratorABC | ||
|
||
is_streaming = isinstance(data, (GeneratorType, AsyncGeneratorABC)) or hasattr(data, '__iter__') and not isinstance(data, str) | ||
|
||
if is_streaming: | ||
# For streaming responses, don't process with output_processors immediately | ||
# The streaming data should be consumed by the caller | ||
log.debug("Streaming response detected, skipping output processors") | ||
output.data = None # Will be populated when stream is consumed | ||
else: | ||
output.data = data | ||
# Non-streaming response processing | ||
if self.output_processors: | ||
if data: | ||
try: | ||
data = self.output_processors(data) | ||
output.data = data | ||
except Exception as e: | ||
log.error(f"Error processing the output processors: {e}") | ||
output.error = str(e) | ||
else: | ||
output.data = data | ||
|
||
return output | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.