[Bugfix][Frontend] Reject Cohere REQUIRED tool choice without tools (#61825)

Signed-off-by: Kevin <jia__kuan@163.com>
This commit is contained in:
Jovan
2026-10-15 16:37:08 +00:00
committed by GitHub
parent d6f0b7a416
commit a9e90b9d1d
3 changed files with 47 additions and 1 deletions
+11 -1
View File
@@ -44,7 +44,7 @@ from cohere.types import (
ToolV2,
UserChatMessageV2,
)
from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, Field, field_validator, model_validator
import vllm.envs as envs
from vllm.exceptions import VLLMValidationError
@@ -211,6 +211,16 @@ class CohereChatV2Request(BaseModel):
)
return v
@model_validator(mode="after")
def _validate_tool_choice(self) -> CohereChatV2Request:
if self.tool_choice == "REQUIRED" and not self.tools:
raise VLLMValidationError(
'tool_choice="REQUIRED" requires at least one tool in tools.',
parameter="tool_choice",
value=self.tool_choice,
)
return self
@field_validator("messages", mode="before")
@classmethod
def _normalize_message_roles(cls, v: Any) -> Any: