[Frontend] Support CustomToolCall in the non-Harmony Responses API (#57322)

Signed-off-by: Shijin Zhang <75300765+Dovis01@users.noreply.github.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
Shijin Zhang
2026-10-12 17:22:55 +08:00
committed by GitHub
co-authored by Chauncey
parent a33d46b471
commit 83773ecdf3
22 changed files with 698 additions and 72 deletions
+35 -3
View File
@@ -14,6 +14,8 @@ from openai.types.responses import (
ResponseCodeInterpreterCallInterpretingEvent,
ResponseContentPartAddedEvent,
ResponseContentPartDoneEvent,
ResponseCustomToolCallInputDeltaEvent,
ResponseCustomToolCallInputDoneEvent,
ResponseFunctionToolCall,
ResponseInputItemParam,
ResponseMcpCallArgumentsDeltaEvent,
@@ -699,6 +701,34 @@ class ResponsesRequest(OpenAIBaseModel):
data["input"] = processed_input
return data
@model_validator(mode="before")
@classmethod
def check_custom_tool_format(cls, data):
if not isinstance(data, dict):
return data
tools = data.get("tools")
if not isinstance(tools, list):
return data
for tool in tools:
if isinstance(tool, dict):
tool_dict = tool
elif hasattr(tool, "model_dump"):
tool_dict = tool.model_dump()
else:
continue
tool_format = tool_dict.get("format")
if (
tool_dict.get("type") == "custom"
and isinstance(tool_format, dict)
and tool_format.get("type") == "grammar"
):
raise VLLMValidationError(
"Custom tools with a grammar format are not supported; "
"only free-form text custom tools are accepted.",
parameter="tools",
)
return data
@model_validator(mode="before")
@classmethod
def check_tool_usage(cls, data):
@@ -708,9 +738,9 @@ class ResponsesRequest(OpenAIBaseModel):
tools = data.get("tools")
tool_choice = data.get("tool_choice", "auto")
has_tools = tools is not None and len(tools) > 0
is_named_tool_choice = (
isinstance(tool_choice, dict) and tool_choice.get("type") == "function"
)
is_named_tool_choice = isinstance(tool_choice, dict) and tool_choice.get(
"type"
) in ("function", "custom")
if not has_tools:
if tool_choice in ("auto", "none"):
@@ -913,6 +943,8 @@ StreamingResponsesResponse: TypeAlias = (
| ResponseOutputItemDoneEvent
| ResponseContentPartAddedEvent
| ResponseContentPartDoneEvent
| ResponseCustomToolCallInputDeltaEvent
| ResponseCustomToolCallInputDoneEvent
| ResponseReasoningTextDeltaEvent
| ResponseReasoningTextDoneEvent
| ResponseCodeInterpreterCallInProgressEvent