File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 55from openai .types .responses .response_function_tool_call_output_item import (
66 ResponseFunctionToolCallOutputItem ,
77)
8+ from openai .types .responses .response_output_message import ResponseOutputMessage
9+ from openai .types .responses .response_output_text import ResponseOutputText
810from openai .types .responses .response_reasoning_item import (
911 Content ,
1012 ResponseReasoningItem ,
@@ -101,3 +103,22 @@ def test_construct_chat_message_with_tool_call(self):
101103 )
102104 with pytest .raises (ValueError ):
103105 construct_chat_message_with_tool_call (item )
106+
107+ output_item = ResponseOutputMessage (
108+ id = "msg_bf585bbbe3d500e0" ,
109+ content = [
110+ ResponseOutputText (
111+ annotations = [],
112+ text = "dongyi" ,
113+ type = "output_text" ,
114+ logprobs = None ,
115+ )
116+ ],
117+ role = "assistant" ,
118+ status = "completed" ,
119+ type = "message" ,
120+ )
121+
122+ formatted_item = construct_chat_message_with_tool_call (output_item )
123+ assert formatted_item ["role" ] == "assistant"
124+ assert formatted_item ["content" ] == "dongyi"
Original file line number Diff line number Diff line change @@ -97,13 +97,18 @@ def construct_chat_message_with_tool_call(
9797 "role" : "assistant" ,
9898 "reasoning" : reasoning_content ,
9999 }
100+ elif isinstance (item , ResponseOutputMessage ):
101+ return {
102+ "role" : "assistant" ,
103+ "content" : item .content [0 ].text ,
104+ }
100105 elif isinstance (item , ResponseFunctionToolCallOutputItem ):
101106 return ChatCompletionToolMessageParam (
102107 role = "tool" ,
103108 content = item .output ,
104109 tool_call_id = item .call_id ,
105110 )
106- elif item .get ("type" ) == "function_call_output" :
111+ elif isinstance ( item , dict ) and item .get ("type" ) == "function_call_output" :
107112 # Append the function call output as a tool message.
108113 return ChatCompletionToolMessageParam (
109114 role = "tool" ,
You can’t perform that action at this time.
0 commit comments