[Frontend] Align tool_choice="required" behavior with OpenAI when tools is empty (#21052)

Signed-off-by: Sungyoon Jeong <sungyoon.jeong@furiosa.ai>
This commit is contained in:
Sungyoon Jeong
2025-08-01 16:54:17 +09:00
committed by GitHub
parent e0f63e4a35
commit 98df153abf

View File

@ -859,6 +859,15 @@ class ChatCompletionRequest(OpenAIBaseModel):
'are supported.'
)
# if tool_choice is "required" but the "tools" list is empty,
# override the data to behave like "none" to align with
# OpenAIs behavior.
if data["tool_choice"] == "required" and isinstance(
data["tools"], list) and len(data["tools"]) == 0:
data["tool_choice"] = "none"
del data["tools"]
return data
# ensure that if "tool_choice" is specified as an object,
# it matches a valid tool
correct_usage_message = 'Correct usage: `{"type": "function",' \