Skip to content

Commit 760ff18

Browse files
committed
修复一个循环的Bug
1 parent 9905122 commit 760ff18

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

request_llm/bridge_chatgpt.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
7272

7373
stream_response = response.iter_lines()
7474
result = ''
75+
json_data = None
7576
while True:
7677
try: chunk = next(stream_response).decode()
7778
except StopIteration:
@@ -90,20 +91,21 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="",
9091
delta = json_data["delta"]
9192
if len(delta) == 0: break
9293
if "role" in delta: continue
93-
if "content" in delta:
94+
if "content" in delta:
9495
result += delta["content"]
9596
if not console_slience: print(delta["content"], end='')
9697
if observe_window is not None:
9798
# 观测窗,把已经获取的数据显示出去
98-
if len(observe_window) >= 1: observe_window[0] += delta["content"]
99+
if len(observe_window) >= 1:
100+
observe_window[0] += delta["content"]
99101
# 看门狗,如果超过期限没有喂狗,则终止
100-
if len(observe_window) >= 2:
102+
if len(observe_window) >= 2:
101103
if (time.time()-observe_window[1]) > watch_dog_patience:
102104
raise RuntimeError("用户取消了程序。")
103105
else: raise RuntimeError("意外Json结构:"+delta)
104-
if json_data['finish_reason'] == 'content_filter':
106+
if json_data and json_data['finish_reason'] == 'content_filter':
105107
raise RuntimeError("由于提问含不合规内容被Azure过滤。")
106-
if json_data['finish_reason'] == 'length':
108+
if json_data and json_data['finish_reason'] == 'length':
107109
raise ConnectionAbortedError("正常结束,但显示Token不足,导致输出不完整,请削减单次输入的文本量。")
108110
return result
109111

0 commit comments

Comments
 (0)