Skip to content

Only include stream_options when streaming #519

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

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ async def _fetch_response(
reasoning_effort = model_settings.reasoning.effort if model_settings.reasoning else None
store = _Converter.get_store_param(self._get_client(), model_settings)

stream_options = _Converter.get_stream_options_param(self._get_client(), model_settings)
stream_options = _Converter.get_stream_options_param(
self._get_client(), model_settings, stream=stream
)

ret = await self._get_client().chat.completions.create(
model=self.model,
Expand Down Expand Up @@ -591,8 +593,11 @@ def get_store_param(cls, client: AsyncOpenAI, model_settings: ModelSettings) ->

@classmethod
def get_stream_options_param(
cls, client: AsyncOpenAI, model_settings: ModelSettings
cls, client: AsyncOpenAI, model_settings: ModelSettings, stream: bool
Copy link
Contributor

@pakrym-oai pakrym-oai Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uber nit: isn't it easier to do _Converter.get_stream_options_param() if stream else None in the method above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO no because this way the logic for stream_options is all in one place

) -> dict[str, bool] | None:
if not stream:
return None

default_include_usage = True if cls.is_openai(client) else None
include_usage = (
model_settings.include_usage
Expand Down