[Bugfix][Frontend] Emit non-ASCII tool-call arguments without \uXXXX escapes (#46308)

Signed-off-by: EazyReal <8047065+EazyReal@users.noreply.github.com>
Co-authored-by: EazyReal <8047065+EazyReal@users.noreply.github.com>
This commit is contained in:
Maxwill Lin
2026-06-23 20:43:11 +00:00
committed by GitHub
co-authored by EazyReal
parent 899d72a58c
commit 6617db1bfb
6 changed files with 75 additions and 9 deletions
@@ -532,3 +532,26 @@ def test_extract_tool_calls_streaming_incremental(
parsed_args = json.loads(full_args)
expected_args = json.loads(expected_first_tool.function.arguments)
assert parsed_args == expected_args
@pytest.mark.parametrize("streaming", [False, True])
def test_extract_tool_calls_non_ascii(xlam_tool_parser, xlam_tokenizer, streaming):
# Use parallel tool calls so the streaming path re-serializes arguments
# (the ensure_ascii fix only runs when tool_count > 1).
model_output = """[{"name": "get_current_weather", "arguments": {"city": "北京"}}, {"name": "get_current_weather", "arguments": {"city": "上海"}}]""" # noqa: E501
if streaming:
request = ChatCompletionRequest(model=MODEL, messages=[])
args = "".join(
delta.tool_calls[0].function.arguments
for delta in stream_delta_message_generator(
xlam_tool_parser, xlam_tokenizer, model_output, request
)
if delta.tool_calls and delta.tool_calls[0].function.arguments
)
else:
extracted = xlam_tool_parser.extract_tool_calls(model_output, request=None) # type: ignore[arg-type]
args = "".join(tc.function.arguments for tc in extracted.tool_calls)
assert "北京" in args
assert "\\u" not in args