mirror of
https://github.com/vllm-project/vllm.git
synced 2025-10-20 14:53:52 +08:00
[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:
@ -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
|
||||
# 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,
|
||||
# it matches a valid tool
|
||||
correct_usage_message = 'Correct usage: `{"type": "function",' \
|
||||
|
Reference in New Issue
Block a user