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(
266
266
stream = True ,
267
267
)
268
268
269
- message = {"role" : "unknown" , "content" : "" }
269
+ message : Dict [ str , Any ] = {"role" : "unknown" , "content" : "" }
270
270
final_tool_calls : Dict [int , ChatCompletionStreamOutputDeltaToolCall ] = {}
271
271
num_of_chunks = 0
272
272
@@ -304,7 +304,26 @@ async def process_single_turn_with_tools(
304
304
# Yield each chunk to caller
305
305
yield chunk
306
306
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
308
327
messages .append (message )
309
328
310
329
# Process tool calls one by one
You can’t perform that action at this time.
0 commit comments