[Bugfix][Responses API] Fix streaming tool calls on /v1/responses (#39892)

Signed-off-by: Hoang Nguyen <118159510+hnt2601@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Hoang Nguyen
2026-04-20 11:24:52 +08:00
committed by GitHub
co-authored by Claude
parent fcb31c1ac3
commit 6e10cb54f6
3 changed files with 137 additions and 13 deletions
+14 -7
View File
@@ -103,13 +103,20 @@ class ToolParser:
)
request.response_format = None
if isinstance(request, ResponsesRequest):
request.text = ResponseTextConfig()
request.text.format = ResponseFormatTextJSONSchemaConfig(
name="tool_calling_response",
schema=json_schema_from_tool,
type="json_schema",
description="Response format for tool calling",
strict=True,
# Single-shot construction so Pydantic v2 tracks `format`
# in __fields_set__ — assigning to `.format` after the bare
# `ResponseTextConfig()` constructor does not, which can
# drop the nested config from `model_dump`. Also drop the
# `description` kwarg: it is not a field on
# ResponseFormatTextJSONSchemaConfig and was being silently
# passed through as extra.
request.text = ResponseTextConfig(
format=ResponseFormatTextJSONSchemaConfig(
type="json_schema",
name="tool_calling_response",
schema=json_schema_from_tool,
strict=True,
)
)
return request
+7 -6
View File
@@ -360,12 +360,13 @@ class Gemma4ToolParser(ToolParser):
self, request: ChatCompletionRequest | ResponsesRequest
) -> ChatCompletionRequest | ResponsesRequest:
request = super().adjust_request(request)
if (
isinstance(request, ChatCompletionRequest)
and request.tools
and request.tool_choice != "none"
):
# Don't skip special tokens — <|tool_call> etc. are needed
if request.tools and request.tool_choice != "none":
# Don't skip special tokens — <|tool_call> etc. are needed for
# the parser to detect tool calls. Apply to BOTH
# ChatCompletionRequest and ResponsesRequest (the previous
# isinstance(ChatCompletionRequest) guard caused tool-call
# delimiters to be stripped on /v1/responses, leaking raw
# `call:fn{...}` text via output_text.delta).
request.skip_special_tokens = False
return request