-
Notifications
You must be signed in to change notification settings - Fork 530
fix(models): Add non-streaming support to OpenAIModel #942
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?
Conversation
|
Wanted to follow up on this, could you take a look at this @zastrowm. Thanks. |
Unshure
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an integration test for this code as well?
src/strands/models/openai.py
Outdated
|
|
||
| model_id: str | ||
| params: Optional[dict[str, Any]] | ||
| streaming: Optional[bool] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| streaming: Optional[bool] | |
| streaming: bool | None |
src/strands/models/openai.py
Outdated
| "model": self.config["model_id"], | ||
| "stream": True, | ||
| # Use configured streaming flag; default True to preserve previous behavior. | ||
| "stream": bool(self.get_config().get("streaming", True)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "stream": bool(self.get_config().get("streaming", True)), | |
| "stream": self.config.get("streaming"), |
Can you update this throughout the pr as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Unshure I've simplified the code to use self.config.get("streaming") as suggested. However, I kept the , True default parameter because without it, the default behavior becomes non-streaming, wouldn't it become a breaking change for existing users?
src/strands/models/litellm.py
Outdated
| streaming: Optional flag to indicate whether provider streaming should be used. | ||
| If omitted, defaults to True (preserves existing behaviour). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this in this pr? Can we punt Litellm non-streaming to another pr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes will remove it since this pr is about OpenAI, should I create another pr for Litellm non-streaming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the pre-commit check is failing with a mypy error on the get_config method in LiteLLMModel. This was because removing the streaming field from LiteLLMConfig (as you requested) made its signature incompatible with the overridden method in OpenAIModel. So, to resolve it, I told mypy to ignore it.
Will do |
2f670b4 to
6a3f111
Compare
|
Hello @Unshure , I wanted to follow up on this. lmk if you need more changes, thanks. |
This commit introduces a streaming parameter to OpenAIModel to allow for non-streaming responses. The initial implementation revealed a type incompatibility in the inheriting LiteLLMModel. This has been resolved by updating LiteLLMConfig to be consistent with the parent OpenAIConfig, ensuring all pre-commit checks pass. The associated unit tests for OpenAIModel have also been improved to verify the non-streaming behavior.
6a3f111 to
0db7641
Compare
|
Hello @Unshure , a gentle remainder about this . Thanks |
Description
This pull request adds support for non-streaming responses to the OpenAIModel. Users can now set streaming=False during model initialization to receive a single, complete response object instead of an event stream.Key Changes
src/strands/models/openai.py:
Added optional streaming: Optional[bool] config key.
format_request now respects streaming (defaults to True to preserve existing behavior).
Stream method supports both streaming and non-streaming flows (converts non-streaming provider response into streaming-style events).
Small helper _convert_non_streaming_to_streaming added to normalize non-streaming responses into the same event format.
src/strands/models/litellm.py:
tests/strands/models/test_openai.py:
Related Issues
Closes #778Documentation PR
N/AType of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.