File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
src/huggingface_hub/inference/_mcp Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -266,7 +266,7 @@ async def process_single_turn_with_tools(
266266 stream = True ,
267267 )
268268
269- message = {"role" : "unknown" , "content" : "" }
269+ message : Dict [ str , Any ] = {"role" : "unknown" , "content" : "" }
270270 final_tool_calls : Dict [int , ChatCompletionStreamOutputDeltaToolCall ] = {}
271271 num_of_chunks = 0
272272
@@ -304,7 +304,26 @@ async def process_single_turn_with_tools(
304304 # Yield each chunk to caller
305305 yield chunk
306306
307- if message ["content" ]:
307+ # Add the assistant message with tool calls (if any) to messages
308+ if message ["content" ] or final_tool_calls :
309+ # if the role is unknown, set it to assistant
310+ if message .get ("role" ) == "unknown" :
311+ message ["role" ] = "assistant"
312+ # Convert final_tool_calls to the format expected by OpenAI
313+ if final_tool_calls :
314+ tool_calls_list : List [Dict [str , Any ]] = []
315+ for tc in final_tool_calls .values ():
316+ tool_calls_list .append (
317+ {
318+ "id" : tc .id ,
319+ "type" : "function" ,
320+ "function" : {
321+ "name" : tc .function .name ,
322+ "arguments" : tc .function .arguments or "{}" ,
323+ },
324+ }
325+ )
326+ message ["tool_calls" ] = tool_calls_list
308327 messages .append (message )
309328
310329 # Process tool calls one by one
You can’t perform that action at this time.
0 commit comments