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 @@ -486,6 +486,8 @@ class TextPart:
486
486
part_kind : Literal ['text' ] = 'text'
487
487
"""Part type identifier, this is available on all parts as a discriminator."""
488
488
489
+ id : str | None = None
490
+
489
491
def has_content (self ) -> bool :
490
492
"""Return `True` if the text content is non-empty."""
491
493
return bool (self .content )
@@ -504,6 +506,8 @@ class ThinkingPart:
504
506
part_kind : Literal ['thinking' ] = 'thinking'
505
507
"""Part type identifier, this is available on all parts as a discriminator."""
506
508
509
+ id : str | None = None
510
+
507
511
def has_content (self ) -> bool :
508
512
"""Return `True` if the thinking content is non-empty."""
509
513
return bool (self .content )
Original file line number Diff line number Diff line change @@ -727,7 +727,21 @@ async def _map_messages(
727
727
elif isinstance (message , ModelResponse ):
728
728
for item in message .parts :
729
729
if isinstance (item , TextPart ):
730
- openai_messages .append (responses .EasyInputMessageParam (role = 'assistant' , content = item .content ))
730
+ openai_messages .append (
731
+ responses .ResponseOutputMessageParam (
732
+ id = item .id or '' ,
733
+ role = 'assistant' ,
734
+ content = [
735
+ responses .ResponseOutputTextParam (
736
+ text = item .content ,
737
+ type = 'output_text' ,
738
+ annotations = [],
739
+ )
740
+ ],
741
+ status = 'completed' ,
742
+ type = 'message' ,
743
+ )
744
+ )
731
745
elif isinstance (item , ToolCallPart ):
732
746
openai_messages .append (self ._map_tool_call (item ))
733
747
elif isinstance (item , ThinkingPart ):
@@ -952,7 +966,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
952
966
pass
953
967
954
968
elif isinstance (chunk , responses .ResponseTextDeltaEvent ):
955
- yield self ._parts_manager .handle_text_delta (vendor_part_id = chunk .content_index , content = chunk .delta )
969
+ yield self ._parts_manager .handle_text_delta (vendor_part_id = chunk .item_id , content = chunk .delta )
956
970
957
971
elif isinstance (chunk , responses .ResponseReasoningSummaryTextDeltaEvent ):
958
972
yield self ._parts_manager .handle_thinking_delta (
You can’t perform that action at this time.
0 commit comments