Browse Source

Merge pull request #1022 from Ikaros-521/owner

修复:因为对接智谱 智能体 导致其他流式数据解析不兼容问题的修复(仅对智能体做特殊解析)
Ikaros 14 hours ago
parent
commit
abfdd223c7
1 changed files with 7 additions and 2 deletions
  1. 7 2
      utils/my_handle.py

+ 7 - 2
utils/my_handle.py

@@ -1697,14 +1697,19 @@ class My_handle(metaclass=SingletonMeta):
 
                 # 已经切掉的字符长度,针对一些特殊llm的流式输出,需要去掉前面的字符
                 cut_len = 0
-                for chunk in resp.iter_lines():
+
+                # 智谱 智能体情况特殊处理
+                if chat_type == "zhipu" and My_handle.config.get("zhipu", "model") == "智能体":
+                    resp = resp.iter_lines()
+
+                for chunk in resp:
                     # logger.warning(chunk)
                     if chunk is None:
                         continue
 
                     if chat_type in ["chatgpt", "zhipu"]:
                         # 智谱 智能体情况特殊处理
-                        if chat_type == "zhipu" and My_handle.config.get("zhipu", "model"):
+                        if chat_type == "zhipu" and My_handle.config.get("zhipu", "model") == "智能体":
                             decoded_line = chunk.decode('utf-8')
                             if decoded_line.startswith('data:'):
                                 data_dict = json.loads(decoded_line[5:])