Skip to content

Commit 5a88d0e

Browse files
committed
add reasoning content to ChatCompletions
using getattr to access reasoning_content check if hasattr reasoning_content
1 parent d0693a1 commit 5a88d0e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/agents/models/openai_chatcompletions.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,13 @@ async def stream_response(
208208
continue
209209

210210
delta = chunk.choices[0].delta
211+
if hasattr(delta, "reasoning_content"):
212+
content = delta.reasoning_content if delta.reasoning_content else delta.content
213+
else:
214+
content = delta.content
211215

212216
# Handle text
213-
if delta.content:
217+
if content:
214218
if not state.text_content_index_and_output:
215219
# Initialize a content tracker for streaming text
216220
state.text_content_index_and_output = (
@@ -249,13 +253,13 @@ async def stream_response(
249253
# Emit the delta for this segment of content
250254
yield ResponseTextDeltaEvent(
251255
content_index=state.text_content_index_and_output[0],
252-
delta=delta.content,
256+
delta=content,
253257
item_id=FAKE_RESPONSES_ID,
254258
output_index=0,
255259
type="response.output_text.delta",
256260
)
257261
# Accumulate the text into the response part
258-
state.text_content_index_and_output[1].text += delta.content
262+
state.text_content_index_and_output[1].text += content
259263

260264
# Handle refusals (model declines to answer)
261265
if delta.refusal:

0 commit comments

Comments
 (0)