Skip to content

Commit 00412a1

Browse files
authored
Fix #1227 Chat Completions model fails to handle streaming with openai 1.97.1+ (#1246)
This pull request resolves #1227
1 parent 7b84678 commit 00412a1

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires-python = ">=3.9"
77
license = "MIT"
88
authors = [{ name = "OpenAI", email = "[email protected]" }]
99
dependencies = [
10-
"openai>=1.96.1, <2",
10+
"openai>=1.97.1,<2",
1111
"pydantic>=2.10, <3",
1212
"griffe>=1.5.6, <2",
1313
"typing-extensions>=4.12.2, <5",

src/agents/models/chatcmpl_stream_handler.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ async def handle_stream(
198198
is not None, # fixed 0 -> 0 or 1
199199
type="response.output_text.delta",
200200
sequence_number=sequence_number.get_and_increment(),
201+
logprobs=[],
201202
)
202203
# Accumulate the text into the response part
203204
state.text_content_index_and_output[1].text += delta.content
@@ -288,10 +289,11 @@ async def handle_stream(
288289
function_call = state.function_calls[tc_delta.index]
289290

290291
# Start streaming as soon as we have function name and call_id
291-
if (not state.function_call_streaming[tc_delta.index] and
292-
function_call.name and
293-
function_call.call_id):
294-
292+
if (
293+
not state.function_call_streaming[tc_delta.index]
294+
and function_call.name
295+
and function_call.call_id
296+
):
295297
# Calculate the output index for this function call
296298
function_call_starting_index = 0
297299
if state.reasoning_content_index_and_output:
@@ -308,9 +310,9 @@ async def handle_stream(
308310

309311
# Mark this function call as streaming and store its output index
310312
state.function_call_streaming[tc_delta.index] = True
311-
state.function_call_output_idx[
312-
tc_delta.index
313-
] = function_call_starting_index
313+
state.function_call_output_idx[tc_delta.index] = (
314+
function_call_starting_index
315+
)
314316

315317
# Send initial function call added event
316318
yield ResponseOutputItemAddedEvent(
@@ -327,10 +329,11 @@ async def handle_stream(
327329
)
328330

329331
# Stream arguments if we've started streaming this function call
330-
if (state.function_call_streaming.get(tc_delta.index, False) and
331-
tc_function and
332-
tc_function.arguments):
333-
332+
if (
333+
state.function_call_streaming.get(tc_delta.index, False)
334+
and tc_function
335+
and tc_function.arguments
336+
):
334337
output_index = state.function_call_output_idx[tc_delta.index]
335338
yield ResponseFunctionCallArgumentsDeltaEvent(
336339
delta=tc_function.arguments,

tests/voice/test_workflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ async def stream_response(
8686
output_index=0,
8787
item_id=item.id,
8888
sequence_number=0,
89+
logprobs=[],
8990
)
9091

9192
yield ResponseCompletedEvent(

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)