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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user