Skip to content

Commit

Permalink
Merge pull request #1096 from lichengzhe/master
Browse files Browse the repository at this point in the history
处理cloudflare Bad Gateway异常,自动重试。
  • Loading branch information
lanvent committed May 15, 2023
2 parents e595972 + 2d7dd71 commit a3819d8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bot/chatgpt/chat_gpt_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ def reply_text(self, session: ChatGPTSession, api_key=None, retry_count=0) -> di
result["content"] = "我没有收到你的消息"
if need_retry:
time.sleep(5)
elif isinstance(e, openai.error.APIError):
logger.warn("[CHATGPT] Bad Gateway: {}".format(e))
result["content"] = "请再问我一次"
if need_retry:
time.sleep(10)
elif isinstance(e, openai.error.APIConnectionError):
logger.warn("[CHATGPT] APIConnectionError: {}".format(e))
need_retry = False
result["content"] = "我连接不到你的网络"
else:
logger.warn("[CHATGPT] Exception: {}".format(e))
logger.exception("[CHATGPT] Exception: {}".format(e))
need_retry = False
self.sessions.clear_session(session.session_id)

Expand Down

0 comments on commit a3819d8

Please sign in to comment.