[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
@@ -1,13 +1,17 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
from openai_harmony import (
Message,
)
from pydantic import ValidationError
from vllm.entrypoints.openai.responses.protocol import (
ResponsesRequest,
serialize_message,
serialize_messages,
)
from vllm.exceptions import VLLMValidationError
def test_serialize_message() -> None:
@@ -37,3 +41,34 @@ def test_serialize_messages() -> None:
}
msg = Message.from_dict(msg_value)
assert serialize_messages([msg, dict_value]) == [msg_value, dict_value]
def test_custom_tool_grammar_format_rejected() -> None:
grammar = {"type": "grammar", "syntax": "lark", "definition": 'start: "pwd"'}
with pytest.raises(VLLMValidationError) as exc_info:
ResponsesRequest(
input="hi", tools=[{"type": "custom", "name": "emit", "format": grammar}]
)
assert exc_info.value.parameter == "tools"
request = ResponsesRequest(
input="hi",
tools=[{"type": "custom", "name": "emit", "format": {"type": "text"}}],
)
assert request.tools is not None and request.tools[0].type == "custom"
@pytest.mark.parametrize(
"tools",
[
"abc",
{"type": "custom"},
[None],
[{"type": "custom", "name": "x", "format": "text"}],
],
)
def test_malformed_tools_rejected_by_field_validation(tools) -> None:
"""Malformed tools bodies fail pydantic field validation (4xx), not an
AttributeError inside the custom-format validator (500)."""
with pytest.raises(ValidationError):
ResponsesRequest(input="hi", tools=tools)