GLM4 tool parser: fix streaming mode (#35208)

Signed-off-by: Robin Nabel <opensource@nabel.co>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
Robin Nabel
2026-03-16 11:48:52 +01:00
committed by GitHub
parent ad041c79db
commit bf9a185395
2 changed files with 26 additions and 10 deletions

View File

@@ -337,10 +337,10 @@ class Glm4MoeModelToolParser(ToolParser):
key_json = json.dumps(key, ensure_ascii=False)
if not self._args_started[self.current_tool_id]:
frag = "{" + key_json + ':"'
frag = "{" + key_json + ': "'
self._args_started[self.current_tool_id] = True
else:
frag = "," + key_json + ':"'
frag = ", " + key_json + ': "'
self.streamed_args_for_tool[self.current_tool_id] += frag
self._streaming_string_value = True
@@ -447,6 +447,10 @@ class Glm4MoeModelToolParser(ToolParser):
self.current_tool_id -= 1
def _emit_tool_name_delta(self, tool_name: str) -> DeltaMessage:
self.prev_tool_call_arr[self.current_tool_id] = {
"name": self._current_tool_name,
"arguments": {},
}
return DeltaMessage(
tool_calls=[
DeltaToolCall(
@@ -493,10 +497,10 @@ class Glm4MoeModelToolParser(ToolParser):
val_json = json.dumps(val_obj, ensure_ascii=False)
if not self._args_started[self.current_tool_id]:
fragment = "{" + key_json + ":" + val_json
fragment = "{" + key_json + ": " + val_json
self._args_started[self.current_tool_id] = True
else:
fragment = "," + key_json + ":" + val_json
fragment = "," + key_json + ": " + val_json
self._seen_keys[self.current_tool_id].add(key)
self.streamed_args_for_tool[self.current_tool_id] += fragment