fix(openai): tolerate empty content in forced tool choice (#40148)

Signed-off-by: QwertyJack <7554089+QwertyJack@users.noreply.github.com>
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
Co-authored-by: QwertyJack <7554089+QwertyJack@users.noreply.github.com>
Co-authored-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
jack
2026-05-06 07:16:03 -07:00
committed by GitHub
co-authored by QwertyJack chaunceyjiang
parent df8e63f4ed
commit 6467213a9f
5 changed files with 109 additions and 7 deletions
@@ -1307,8 +1307,8 @@ class OpenAIServingChat(OpenAIServing):
request.tool_choice
and type(request.tool_choice) is ChatCompletionNamedToolChoiceParam
):
assert tool_calls is not None and len(tool_calls) > 0
tool_call_class_items = []
tool_calls = tool_calls or []
for idx, tc in enumerate(tool_calls):
# Use native ID if available (e.g., Kimi K2),
# otherwise generate ID with correct id_type
+4 -2
View File
@@ -638,8 +638,9 @@ class OpenAIServing:
and request.tool_choice
and isinstance(request.tool_choice, ToolChoiceFunction)
):
assert content is not None
# Forced Function Call (Responses API)
if content is None:
return [], None
function_calls.append(
FunctionCall(name=request.tool_choice.name, arguments=content)
)
@@ -651,7 +652,8 @@ class OpenAIServing:
and (tool_parser_cls is None or tool_parser_cls.supports_required_and_named)
):
# Named function with standard JSON-based parsing
assert content is not None
if content is None:
return [], None
function_calls.append(
FunctionCall(name=request.tool_choice.function.name, arguments=content)
)