[BugFix] Support tool_choice=none in the Anthropic API (#35835)

Signed-off-by: ZhongsJie <zhongsjie@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
ShiJie Zhong
2026-03-04 13:24:46 +08:00
committed by GitHub
parent 3c85cd9d74
commit 7cdba98edf
2 changed files with 3 additions and 1 deletions

View File

@@ -77,7 +77,7 @@ class AnthropicTool(BaseModel):
class AnthropicToolChoice(BaseModel):
"""Tool Choice definition"""
type: Literal["auto", "any", "tool"]
type: Literal["auto", "any", "tool", "none"]
name: str | None = None
@model_validator(mode="after")

View File

@@ -349,6 +349,8 @@ class AnthropicServingMessages(OpenAIServingChat):
req.tool_choice = "auto"
elif tool_choice_type == "any":
req.tool_choice = "required"
elif tool_choice_type == "none":
req.tool_choice = "none"
elif tool_choice_type == "tool":
req.tool_choice = ChatCompletionNamedToolChoiceParam.model_validate(
{