File tree 3 files changed +21
-3
lines changed
pydantic_ai_slim/pydantic_ai
3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ def handle_text_delta(
111
111
if existing_text_part_and_index is None :
112
112
# There is no existing text part that should be updated, so create a new one
113
113
new_part_index = len (self ._parts )
114
- part = TextPart (content = content )
114
+ part = TextPart (id = vendor_part_id , content = content )
115
115
if vendor_part_id is not None :
116
116
self ._vendor_id_to_part_index [vendor_part_id ] = new_part_index
117
117
self ._parts .append (part )
Original file line number Diff line number Diff line change @@ -476,6 +476,8 @@ class TextPart:
476
476
part_kind : Literal ['text' ] = 'text'
477
477
"""Part type identifier, this is available on all parts as a discriminator."""
478
478
479
+ id : str | None = None
480
+
479
481
def has_content (self ) -> bool :
480
482
"""Return `True` if the text content is non-empty."""
481
483
return bool (self .content )
@@ -494,6 +496,8 @@ class ThinkingPart:
494
496
part_kind : Literal ['thinking' ] = 'thinking'
495
497
"""Part type identifier, this is available on all parts as a discriminator."""
496
498
499
+ id : str | None = None
500
+
497
501
def has_content (self ) -> bool :
498
502
"""Return `True` if the thinking content is non-empty."""
499
503
return bool (self .content )
Original file line number Diff line number Diff line change @@ -725,7 +725,21 @@ async def _map_messages(
725
725
elif isinstance (message , ModelResponse ):
726
726
for item in message .parts :
727
727
if isinstance (item , TextPart ):
728
- openai_messages .append (responses .EasyInputMessageParam (role = 'assistant' , content = item .content ))
728
+ openai_messages .append (
729
+ responses .ResponseOutputMessageParam (
730
+ id = item .id or '' ,
731
+ role = 'assistant' ,
732
+ content = [
733
+ responses .ResponseOutputTextParam (
734
+ text = item .content ,
735
+ type = 'output_text' ,
736
+ annotations = [],
737
+ )
738
+ ],
739
+ status = 'completed' ,
740
+ type = 'message' ,
741
+ )
742
+ )
729
743
elif isinstance (item , ToolCallPart ):
730
744
openai_messages .append (self ._map_tool_call (item ))
731
745
elif isinstance (item , ThinkingPart ):
@@ -950,7 +964,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
950
964
pass
951
965
952
966
elif isinstance (chunk , responses .ResponseTextDeltaEvent ):
953
- yield self ._parts_manager .handle_text_delta (vendor_part_id = chunk .content_index , content = chunk .delta )
967
+ yield self ._parts_manager .handle_text_delta (vendor_part_id = chunk .item_id , content = chunk .delta )
954
968
955
969
elif isinstance (chunk , responses .ResponseReasoningSummaryTextDeltaEvent ):
956
970
yield self ._parts_manager .handle_thinking_delta (
You can’t perform that action at this time.
0 commit comments