Skip to content

add reasoning content to ChatCompletions #494

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions src/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ async def stream_response(
continue

delta = chunk.choices[0].delta
if hasattr(delta, "reasoning_content"):
content = delta.reasoning_content if delta.reasoning_content else delta.content
else:
content = delta.content

# Handle text
if delta.content:
if content:
if not state.text_content_index_and_output:
# Initialize a content tracker for streaming text
state.text_content_index_and_output = (
Expand Down Expand Up @@ -249,13 +253,13 @@ async def stream_response(
# Emit the delta for this segment of content
yield ResponseTextDeltaEvent(
content_index=state.text_content_index_and_output[0],
delta=delta.content,
delta=content,
item_id=FAKE_RESPONSES_ID,
output_index=0,
type="response.output_text.delta",
)
# Accumulate the text into the response part
state.text_content_index_and_output[1].text += delta.content
state.text_content_index_and_output[1].text += content

# Handle refusals (model declines to answer)
if delta.refusal:
Expand Down