rossi913 commited on
Commit
a28ea94
1 Parent(s): d3fe58f

Update modeling_chatglm.py

Browse files

support the stream_chat method for tool invocation.

Files changed (1) hide show
  1. modeling_chatglm.py +13 -5
modeling_chatglm.py CHANGED
@@ -1074,11 +1074,19 @@ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel):
1074
  outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):-1]
1075
  response = tokenizer.decode(outputs)
1076
  if response and response[-1] != "�":
1077
- response, new_history = self.process_response(response, history)
1078
- if return_past_key_values:
1079
- yield response, new_history, past_key_values
1080
- else:
1081
- yield response, new_history
 
 
 
 
 
 
 
 
1082
 
1083
  @torch.inference_mode()
1084
  def stream_generate(
 
1074
  outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):-1]
1075
  response = tokenizer.decode(outputs)
1076
  if response and response[-1] != "�":
1077
+ if response.startswith("\n") or history[0]["role"] != "system" or "tools" not in history[0]:
1078
+ new_response, new_history = self.process_response(response, history)
1079
+ if return_past_key_values:
1080
+ yield new_response, new_history, past_key_values
1081
+ else:
1082
+ yield new_response, new_history
1083
+
1084
+ if response and "new_response" not in locals().keys():
1085
+ new_response, new_history = self.process_response(response, history)
1086
+ if return_past_key_values:
1087
+ yield new_response, new_history, past_key_values
1088
+ else:
1089
+ yield new_response, new_history
1090
 
1091
  @torch.inference_mode()
1092
  def stream_generate(