File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 31
31
from pydantic_ai .messages import (
32
32
ModelMessage ,
33
33
ModelMessagesTypeAdapter ,
34
+ ModelRequest ,
34
35
ModelResponse ,
35
36
TextPart ,
36
37
UserPromptPart ,
@@ -86,14 +87,15 @@ class ChatMessage(TypedDict):
86
87
87
88
88
89
def to_chat_message (m : ModelMessage ) -> ChatMessage :
89
- if isinstance (m , UserPromptPart ):
90
- return {
91
- 'role' : 'user' ,
92
- 'timestamp' : m .timestamp .isoformat (),
93
- 'content' : m .content ,
94
- }
90
+ first_part = m .parts [0 ]
91
+ if isinstance (m , ModelRequest ):
92
+ if isinstance (first_part , UserPromptPart ):
93
+ return {
94
+ 'role' : 'user' ,
95
+ 'timestamp' : first_part .timestamp .isoformat (),
96
+ 'content' : first_part .content ,
97
+ }
95
98
elif isinstance (m , ModelResponse ):
96
- first_part = m .parts [0 ]
97
99
if isinstance (first_part , TextPart ):
98
100
return {
99
101
'role' : 'model' ,
You can’t perform that action at this time.
0 commit comments