[Bugfix] Fix Gemma4ToolParser streaming float corruption (#42128)

Signed-off-by: abinggo <107740309+abinggo@users.noreply.github.com>
This commit is contained in:
longguo
2026-05-13 18:03:30 -07:00
committed by GitHub
parent 1087676a90
commit 665f9c4253
2 changed files with 41 additions and 0 deletions
+12
View File
@@ -211,6 +211,14 @@ def _parse_gemma4_args(args_str: str, *, partial: bool = False) -> dict:
i,
)
break
if partial:
raw_val = args_str[val_start:i].strip()
if raw_val.endswith("."):
# Trailing dot means decimal digits may still arrive
# (e.g. "108." may become "108.2"). Parsing now would
# yield float("108.") == 108.0, whose json repr "108.0"
# corrupts the streaming diff when the true digit lands.
break
result[key] = _parse_gemma4_value(args_str[val_start:i])
return result
@@ -294,6 +302,10 @@ def _parse_gemma4_array(arr_str: str, *, partial: bool = False) -> list:
i,
)
break
if partial:
raw_val = arr_str[val_start:i].strip()
if raw_val.endswith("."):
break
items.append(_parse_gemma4_value(arr_str[val_start:i]))
return items