[Bugfix] Fix Gemma4ToolParser streaming float corruption (#42128)
Signed-off-by: abinggo <107740309+abinggo@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user