Skip to content

Commit 56db7b9

Browse files
committed
Create separate ThinkingParts for separate OpenAI Responses reasoning summary parts
1 parent 55ad5bd commit 56db7b9

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

pydantic_ai_slim/pydantic_ai/models/openai.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,12 +1270,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
12701270
tool_call_id=chunk.item.call_id,
12711271
)
12721272
elif isinstance(chunk.item, responses.ResponseReasoningItem):
1273-
content = chunk.item.summary[0].text if chunk.item.summary else ''
1274-
yield self._parts_manager.handle_thinking_delta(
1275-
vendor_part_id=chunk.item.id,
1276-
content=content,
1277-
signature=chunk.item.id,
1278-
)
1273+
pass
12791274
elif isinstance(chunk.item, responses.ResponseOutputMessage):
12801275
pass
12811276
elif isinstance(chunk.item, responses.ResponseFunctionWebSearch):
@@ -1291,7 +1286,11 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
12911286
pass
12921287

12931288
elif isinstance(chunk, responses.ResponseReasoningSummaryPartAddedEvent):
1294-
pass # there's nothing we need to do here
1289+
yield self._parts_manager.handle_thinking_delta(
1290+
vendor_part_id=f'{chunk.item_id}-{chunk.summary_index}',
1291+
content=chunk.part.text,
1292+
signature=chunk.item_id,
1293+
)
12951294

12961295
elif isinstance(chunk, responses.ResponseReasoningSummaryPartDoneEvent):
12971296
pass # there's nothing we need to do here
@@ -1301,7 +1300,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
13011300

13021301
elif isinstance(chunk, responses.ResponseReasoningSummaryTextDeltaEvent):
13031302
yield self._parts_manager.handle_thinking_delta(
1304-
vendor_part_id=chunk.item_id,
1303+
vendor_part_id=f'{chunk.item_id}-{chunk.summary_index}',
13051304
content=chunk.delta,
13061305
signature=chunk.item_id,
13071306
)
@@ -1311,9 +1310,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
13111310
pass # there's nothing we need to do here
13121311

13131312
elif isinstance(chunk, responses.ResponseTextDeltaEvent):
1314-
maybe_event = self._parts_manager.handle_text_delta(
1315-
vendor_part_id=chunk.content_index, content=chunk.delta
1316-
)
1313+
maybe_event = self._parts_manager.handle_text_delta(vendor_part_id=chunk.item_id, content=chunk.delta)
13171314
if maybe_event is not None: # pragma: no branch
13181315
yield maybe_event
13191316

0 commit comments

Comments
 (0)