Tuchuanhuhuhu commited on
Commit
5613ec0
1 Parent(s): f744196

完善了错误处理

Browse files
Files changed (1) hide show
  1. ChuanhuChatbot.py +10 -2
ChuanhuChatbot.py CHANGED
@@ -113,7 +113,14 @@ def predict(inputs, top_p, temperature, openai_api_key, chatbot=[], history=[],
113
  # check whether each line is non-empty
114
  if chunk:
115
  # decode each line as response data is in bytes
116
- if len(json.loads(chunk.decode()[6:])['choices'][0]["delta"]) == 0:
 
 
 
 
 
 
 
117
  break
118
  #print(json.loads(chunk.decode()[6:])['choices'][0]["delta"] ["content"])
119
  partial_words = partial_words + \
@@ -259,4 +266,5 @@ with gr.Blocks() as demo:
259
  print("川虎的温馨提示:访问 http://localhost:7860 查看界面")
260
  # 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
261
  demo.title = "川虎ChatGPT 🚀"
262
- demo.queue().launch(server_name="127.0.0.1", server_port=7860, share=False) # 改为 share=True 可以创建公开分享链接
 
 
113
  # check whether each line is non-empty
114
  if chunk:
115
  # decode each line as response data is in bytes
116
+ try:
117
+ if len(json.loads(chunk.decode()[6:])['choices'][0]["delta"]) == 0:
118
+ break
119
+ except Exception as e:
120
+ chatbot.pop()
121
+ chatbot.append((history[-1], f"☹️发生了错误\n返回值:{response.text}\n异常:{e}"))
122
+ history.pop()
123
+ yield chatbot, history
124
  break
125
  #print(json.loads(chunk.decode()[6:])['choices'][0]["delta"] ["content"])
126
  partial_words = partial_words + \
 
266
  print("川虎的温馨提示:访问 http://localhost:7860 查看界面")
267
  # 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
268
  demo.title = "川虎ChatGPT 🚀"
269
+ demo.queue().launch(server_name = "0.0.0.0", share=False) # 改为 share=True 可以创建公开分享链接
270
+ # demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口