@@ -351,7 +351,9 @@ async def responses_full_generator(
351
351
outputs .append (reasoning_item )
352
352
if message_item :
353
353
outputs .append (message_item )
354
- elif request .tool_choice is None or request .tool_choice == "none" :
354
+ elif (request .tool_choice == "none" and \
355
+ not self .expand_tools_even_if_tool_choice_none ) or \
356
+ request .tool_choice is None :
355
357
# No tool calls.
356
358
if reasoning_item :
357
359
outputs .append (reasoning_item )
@@ -373,7 +375,7 @@ async def responses_full_generator(
373
375
ensure_ascii = False ))
374
376
for tool_call in tool_calls
375
377
])
376
- elif request .tool_choice == "auto" :
378
+ elif request .tool_choice == "auto" or request . tool_choice == "none" :
377
379
try :
378
380
tool_parser = self .tool_parser (tokenizer )
379
381
except RuntimeError as e :
@@ -382,6 +384,7 @@ async def responses_full_generator(
382
384
tool_call_info = tool_parser .extract_tool_calls (
383
385
content if content is not None else "" , request = request )
384
386
if tool_call_info is not None and tool_call_info .tools_called :
387
+ # extract_tool_calls() returns a list of tool calls.
385
388
function_calls .extend (
386
389
FunctionCall (
387
390
name = tool_call .function .name ,
@@ -477,6 +480,7 @@ def _construct_input_messages(
477
480
else :
478
481
for item in request .input :
479
482
if item .get ("type" ) == "function_call" :
483
+ # Append the function call as a tool call.
480
484
messages .append ({
481
485
"role" :
482
486
"assistant" ,
@@ -490,6 +494,7 @@ def _construct_input_messages(
490
494
}]
491
495
})
492
496
elif item .get ("type" ) == "function_call_output" :
497
+ # Append the function call output as a tool message.
493
498
messages .append ({
494
499
"role" : "tool" ,
495
500
"content" : item .get ("output" , "" ),
0 commit comments