[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:
@@ -7,7 +7,7 @@ from abc import abstractmethod
|
||||
from collections.abc import Sequence
|
||||
from dataclasses import dataclass, field, replace
|
||||
|
||||
from openai.types.responses import ToolChoiceFunction
|
||||
from openai.types.responses import ToolChoiceCustom, ToolChoiceFunction
|
||||
from pydantic import TypeAdapter, ValidationError
|
||||
from xgrammar import Grammar, StructuralTag
|
||||
from xgrammar.structural_tag import (
|
||||
@@ -359,7 +359,9 @@ class DelegatingParser(Parser):
|
||||
def _get_function_name(
|
||||
self, request: ChatCompletionRequest | ResponsesRequest
|
||||
) -> str:
|
||||
if request.tool_choice and isinstance(request.tool_choice, ToolChoiceFunction):
|
||||
if request.tool_choice and isinstance(
|
||||
request.tool_choice, (ToolChoiceFunction, ToolChoiceCustom)
|
||||
):
|
||||
return request.tool_choice.name
|
||||
if request.tool_choice and isinstance(
|
||||
request.tool_choice, ChatCompletionNamedToolChoiceParam
|
||||
@@ -398,7 +400,7 @@ class DelegatingParser(Parser):
|
||||
supports_required_and_named = tool_parser.supports_required_and_named
|
||||
is_named_tool_choice = request.tool_choice and isinstance(
|
||||
request.tool_choice,
|
||||
(ToolChoiceFunction, ChatCompletionNamedToolChoiceParam),
|
||||
(ToolChoiceFunction, ToolChoiceCustom, ChatCompletionNamedToolChoiceParam),
|
||||
)
|
||||
is_required_tool_choice = request.tool_choice == "required"
|
||||
is_auto_tool_choice = enable_auto_tools and (
|
||||
@@ -503,7 +505,11 @@ class DelegatingParser(Parser):
|
||||
or request.tool_choice == "required"
|
||||
or isinstance(
|
||||
request.tool_choice,
|
||||
(ChatCompletionNamedToolChoiceParam, ToolChoiceFunction),
|
||||
(
|
||||
ChatCompletionNamedToolChoiceParam,
|
||||
ToolChoiceFunction,
|
||||
ToolChoiceCustom,
|
||||
),
|
||||
)
|
||||
)
|
||||
if not need_tool_calling:
|
||||
@@ -723,7 +729,11 @@ class DelegatingParser(Parser):
|
||||
and request.tool_choice
|
||||
and isinstance(
|
||||
request.tool_choice,
|
||||
(ToolChoiceFunction, ChatCompletionNamedToolChoiceParam),
|
||||
(
|
||||
ToolChoiceFunction,
|
||||
ToolChoiceCustom,
|
||||
ChatCompletionNamedToolChoiceParam,
|
||||
),
|
||||
)
|
||||
):
|
||||
delta_message, function_name_returned = extract_named_tool_call_streaming(
|
||||
|
||||
@@ -9,7 +9,7 @@ import json
|
||||
from collections.abc import Callable, Iterable, Sequence
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from openai.types.responses import ToolChoiceFunction
|
||||
from openai.types.responses import ToolChoiceCustom, ToolChoiceFunction
|
||||
|
||||
from vllm.entrypoints.generate.base.protocol import (
|
||||
DeltaFunctionCall,
|
||||
@@ -173,7 +173,8 @@ def _streaming_template(template: dict[str, Any]) -> ResponseTemplate:
|
||||
|
||||
def _is_named_tool_choice(request: ChatCompletionRequest | ResponsesRequest) -> bool:
|
||||
return isinstance(
|
||||
request.tool_choice, (ToolChoiceFunction, ChatCompletionNamedToolChoiceParam)
|
||||
request.tool_choice,
|
||||
(ToolChoiceFunction, ToolChoiceCustom, ChatCompletionNamedToolChoiceParam),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user