qingxu99 commited on
Commit
43e6478
1 Parent(s): 5f79fed

修正非官方的OpenAI反代错误显示问题

Browse files
Files changed (1) hide show
  1. request_llm/bridge_chatgpt.py +9 -1
request_llm/bridge_chatgpt.py CHANGED
@@ -168,7 +168,15 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
168
  if stream:
169
  stream_response = response.iter_lines()
170
  while True:
171
- chunk = next(stream_response)
 
 
 
 
 
 
 
 
172
  # print(chunk.decode()[6:])
173
  if is_head_of_the_stream and (r'"object":"error"' not in chunk.decode()):
174
  # 数据流的第一帧不携带content
 
168
  if stream:
169
  stream_response = response.iter_lines()
170
  while True:
171
+ try:
172
+ chunk = next(stream_response)
173
+ except StopIteration:
174
+ # 非OpenAI官方接口的出现这样的报错,OpenAI和API2D不会走这里
175
+ from toolbox import regular_txt_to_markdown; tb_str = '```\n' + trimmed_format_exc() + '```'
176
+ chatbot[-1] = (chatbot[-1][0], f"[Local Message] 远程返回错误: \n\n{tb_str} \n\n{regular_txt_to_markdown(chunk.decode())}")
177
+ yield from update_ui(chatbot=chatbot, history=history, msg="远程返回错误:" + chunk.decode()) # 刷新界面
178
+ return
179
+
180
  # print(chunk.decode()[6:])
181
  if is_head_of_the_stream and (r'"object":"error"' not in chunk.decode()):
182
  # 数据流的第一帧不携带content