[Bugfix] ensure tool_choice is popped when tool_choice:null is passed in json payload (#19679)

Signed-off-by: Guillaume Calmettes <gcalmettes@scaleway.com>
This commit is contained in:
Guillaume Calmettes 2025-07-23 09:30:05 +02:00 committed by GitHub
parent 2f5c14de6a
commit 7aaa2bd5a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -841,7 +841,7 @@ class ChatCompletionRequest(OpenAIBaseModel):
return data
# if "tool_choice" is specified -- validation
if "tool_choice" in data:
if "tool_choice" in data and data["tool_choice"] is not None:
# ensure that if "tool choice" is specified, tools are present
if "tools" not in data or data["tools"] is None:
@ -853,7 +853,7 @@ class ChatCompletionRequest(OpenAIBaseModel):
if data["tool_choice"] not in [
"auto", "required"
] and not isinstance(data["tool_choice"], dict):
raise NotImplementedError(
raise ValueError(
f'Invalid value for `tool_choice`: {data["tool_choice"]}! '\
'Only named tools, "none", "auto" or "required" '\
'are supported.'