Skip to content
Closed
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
24 changes: 8 additions & 16 deletions src/agents/models/chatcmpl_stream_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,14 @@ async def handle_stream(
# Notify consumers of the start of a new output message + first content part
yield ResponseOutputItemAddedEvent(
item=assistant_item,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
type="response.output_item.added",
sequence_number=sequence_number.get_and_increment(),
)
yield ResponseContentPartAddedEvent(
content_index=state.text_content_index_and_output[0],
item_id=FAKE_RESPONSES_ID,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
part=ResponseOutputText(
text="",
type="output_text",
Expand All @@ -374,8 +372,7 @@ async def handle_stream(
content_index=state.text_content_index_and_output[0],
delta=delta.content,
item_id=FAKE_RESPONSES_ID,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
type="response.output_text.delta",
sequence_number=sequence_number.get_and_increment(),
logprobs=delta_logprobs,
Expand Down Expand Up @@ -415,8 +412,7 @@ async def handle_stream(
# Notify downstream that assistant message + first content part are starting
yield ResponseOutputItemAddedEvent(
item=assistant_item,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
type="response.output_item.added",
sequence_number=sequence_number.get_and_increment(),
)
Expand All @@ -436,8 +432,7 @@ async def handle_stream(
content_index=state.refusal_content_index_and_output[0],
delta=delta.refusal,
item_id=FAKE_RESPONSES_ID,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
type="response.refusal.delta",
sequence_number=sequence_number.get_and_increment(),
)
Expand Down Expand Up @@ -603,8 +598,7 @@ async def handle_stream(
yield ResponseContentPartDoneEvent(
content_index=state.text_content_index_and_output[0],
item_id=FAKE_RESPONSES_ID,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
part=state.text_content_index_and_output[1],
type="response.content_part.done",
sequence_number=sequence_number.get_and_increment(),
Expand All @@ -616,8 +610,7 @@ async def handle_stream(
yield ResponseContentPartDoneEvent(
content_index=state.refusal_content_index_and_output[0],
item_id=FAKE_RESPONSES_ID,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
part=state.refusal_content_index_and_output[1],
type="response.content_part.done",
sequence_number=sequence_number.get_and_increment(),
Expand Down Expand Up @@ -747,8 +740,7 @@ async def handle_stream(
# send a ResponseOutputItemDone for the assistant message
yield ResponseOutputItemDoneEvent(
item=assistant_msg,
output_index=state.reasoning_content_index_and_output
is not None, # fixed 0 -> 0 or 1
output_index=(1 if state.reasoning_content_index_and_output else 0),
type="response.output_item.done",
sequence_number=sequence_number.get_and_increment(),
)
Expand Down