File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed
src/huggingface_hub/inference/_mcp Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -286,16 +286,19 @@ async def process_single_turn_with_tools(
286286 # Process tool calls
287287 if delta .tool_calls :
288288 for tool_call in delta .tool_calls :
289- # Aggregate chunks into tool calls
290- if tool_call .index not in final_tool_calls :
291- if (
292- tool_call .function .arguments is None or tool_call .function .arguments == "{}"
293- ): # Corner case (depends on provider)
294- tool_call .function .arguments = ""
295- final_tool_calls [tool_call .index ] = tool_call
296-
297- elif tool_call .function .arguments :
298- final_tool_calls [tool_call .index ].function .arguments += tool_call .function .arguments
289+ idx = tool_call .index
290+ # first chunk for this tool call
291+ if idx not in final_tool_calls :
292+ final_tool_calls [idx ] = tool_call
293+ if final_tool_calls [idx ].function .arguments is None :
294+ final_tool_calls [idx ].function .arguments = ""
295+ continue
296+ # safety before concatenating text to .function.arguments
297+ if final_tool_calls [idx ].function .arguments is None :
298+ final_tool_calls [idx ].function .arguments = ""
299+
300+ if tool_call .function .arguments :
301+ final_tool_calls [idx ].function .arguments += tool_call .function .arguments
299302
300303 # Optionally exit early if no tools in first chunks
301304 if exit_if_first_chunk_no_tool and num_of_chunks <= 2 and len (final_tool_calls ) == 0 :
You can’t perform that action at this time.
0 commit comments