Tuchuanhuhuhu commited on
Commit
108e387
1 Parent(s): be104ff

修复GPT一次回复实在太长时导致的ERROR, fix #141

Browse files
Files changed (1) hide show
  1. utils.py +6 -1
utils.py CHANGED
@@ -169,7 +169,12 @@ def stream_predict(openai_api_key, system_prompt, history, inputs, chatbot, prev
169
  print("生成完毕")
170
  yield get_return_value()
171
  break
172
- partial_words = partial_words + chunk['choices'][0]["delta"]["content"]
 
 
 
 
 
173
  if token_counter == 0:
174
  history.append(construct_assistant(" " + partial_words))
175
  else:
 
169
  print("生成完毕")
170
  yield get_return_value()
171
  break
172
+ try:
173
+ partial_words = partial_words + chunk['choices'][0]["delta"]["content"]
174
+ except KeyError:
175
+ status_text = standard_error_msg + "API回复中找不到内容。很可能是Token计数达到上限了。当前Token计数: " + str(sum(previous_token_count)+token_counter+user_token_count)
176
+ yield get_return_value()
177
+ break
178
  if token_counter == 0:
179
  history.append(construct_assistant(" " + partial_words))
180
  else: