[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:
@@ -29,6 +29,7 @@ from typing import cast
|
||||
import pytest
|
||||
|
||||
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
|
||||
from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
|
||||
from vllm.reasoning.muse_glimmer_reasoning_parser import MuseGlimmerReasoningParser
|
||||
from vllm.tool_parsers.muse_glimmer_tool_parser import MuseGlimmerToolParser
|
||||
|
||||
@@ -400,3 +401,15 @@ def test_exact_match_kept():
|
||||
T, _call("get_weather"), _req("get_weather")
|
||||
)
|
||||
assert out.tool_calls[0].function.name == "get_weather"
|
||||
|
||||
|
||||
def test_named_custom_tool_choice_skips_structured_outputs():
|
||||
# Custom tools ride the function shim; a named custom choice must skip
|
||||
# the base adjust_request like a named function choice does.
|
||||
request = ResponsesRequest(
|
||||
input="hi",
|
||||
tools=[{"type": "custom", "name": "emit_command"}],
|
||||
tool_choice={"type": "custom", "name": "emit_command"},
|
||||
)
|
||||
T.adjust_request(request)
|
||||
assert request.structured_outputs is None
|
||||
|
||||
@@ -6,7 +6,9 @@ from copy import deepcopy
|
||||
import pytest
|
||||
import regex as re
|
||||
from openai.types.responses import (
|
||||
CustomTool,
|
||||
FunctionTool,
|
||||
ToolChoiceCustom,
|
||||
ToolChoiceFunction,
|
||||
WebSearchTool,
|
||||
)
|
||||
@@ -21,8 +23,10 @@ from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.tool_parsers.streaming import extract_required_tool_call_streaming
|
||||
from vllm.tool_parsers.utils import (
|
||||
custom_tool_parameters,
|
||||
find_tool_properties,
|
||||
get_json_schema_from_tools,
|
||||
iter_response_function_tool_dicts,
|
||||
)
|
||||
|
||||
pytestmark = pytest.mark.cpu_test
|
||||
@@ -483,6 +487,37 @@ class TestNonFunctionToolsSkipped:
|
||||
get_json_schema_from_tools(tools=[WEB_SEARCH_TOOL], tool_choice="required")
|
||||
|
||||
|
||||
class TestCustomToolShim:
|
||||
"""``custom`` tools are shown to the model as a single-string function."""
|
||||
|
||||
def test_rendered_as_single_string_function(self):
|
||||
tool = CustomTool(
|
||||
type="custom", name="emit_command", description="Emit a command."
|
||||
)
|
||||
[tool_dict] = iter_response_function_tool_dicts([tool])
|
||||
assert tool_dict["type"] == "function"
|
||||
assert tool_dict["name"] == "emit_command"
|
||||
assert tool_dict["description"] == "Emit a command."
|
||||
assert tool_dict["parameters"] == custom_tool_parameters()
|
||||
assert tool_dict["parameters"]["required"] == ["input"]
|
||||
|
||||
def test_forced_tool_choice_sees_custom_tool(self):
|
||||
tools = [CustomTool(type="custom", name="emit_command"), FUNCTION_TOOL]
|
||||
schema = get_json_schema_from_tools(tools=tools, tool_choice="required")
|
||||
assert isinstance(schema, dict)
|
||||
names = [e["properties"]["name"]["enum"] for e in schema["items"]["anyOf"]]
|
||||
assert names == [["emit_command"], ["get_weather"]]
|
||||
named = get_json_schema_from_tools(
|
||||
tools=tools,
|
||||
tool_choice=ToolChoiceCustom(type="custom", name="emit_command"),
|
||||
)
|
||||
assert named == custom_tool_parameters()
|
||||
assert (
|
||||
find_tool_properties(tools, "emit_command")
|
||||
== custom_tool_parameters()["properties"]
|
||||
)
|
||||
|
||||
|
||||
class TestMalformedToolSchemaDefs:
|
||||
"""Malformed `$defs` in caller-supplied tool parameters is a 400, not a 500."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user