Unverified Commit 98df153a authored by Sungyoon Jeong's avatar Sungyoon Jeong Committed by GitHub
Browse files

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


Signed-off-by: default avatarSungyoon Jeong <sungyoon.jeong@furiosa.ai>
parent e0f63e4a
...@@ -859,6 +859,15 @@ class ChatCompletionRequest(OpenAIBaseModel): ...@@ -859,6 +859,15 @@ class ChatCompletionRequest(OpenAIBaseModel):
'are supported.' 'are supported.'
) )
# if tool_choice is "required" but the "tools" list is empty,
# override the data to behave like "none" to align with
# OpenAI’s 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, # ensure that if "tool_choice" is specified as an object,
# it matches a valid tool # it matches a valid tool
correct_usage_message = 'Correct usage: `{"type": "function",' \ correct_usage_message = 'Correct usage: `{"type": "function",' \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment