Skip to content

Commit 98df153

Browse files
authored
[Frontend] Align tool_choice="required" behavior with OpenAI when tools is empty (#21052)
Signed-off-by: Sungyoon Jeong <[email protected]>
1 parent e0f63e4 commit 98df153

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

vllm/entrypoints/openai/protocol.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,15 @@ def check_tool_usage(cls, data):
859859
'are supported.'
860860
)
861861

862+
# if tool_choice is "required" but the "tools" list is empty,
863+
# override the data to behave like "none" to align with
864+
# OpenAI’s behavior.
865+
if data["tool_choice"] == "required" and isinstance(
866+
data["tools"], list) and len(data["tools"]) == 0:
867+
data["tool_choice"] = "none"
868+
del data["tools"]
869+
return data
870+
862871
# ensure that if "tool_choice" is specified as an object,
863872
# it matches a valid tool
864873
correct_usage_message = 'Correct usage: `{"type": "function",' \

0 commit comments

Comments
 (0)