From a2db765aded5306786352b2c86088a01834ad16e Mon Sep 17 00:00:00 2001 From: "sunxin.181" Date: Sat, 4 Mar 2023 21:02:48 +0800 Subject: [PATCH] [feat] catch connection failed exception --- bot/chatgpt/chat_gpt_bot.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bot/chatgpt/chat_gpt_bot.py b/bot/chatgpt/chat_gpt_bot.py index d94667e..f883d7d 100644 --- a/bot/chatgpt/chat_gpt_bot.py +++ b/bot/chatgpt/chat_gpt_bot.py @@ -63,6 +63,15 @@ class ChatGPTBot(Bot): return self.reply_text(query, user_id, retry_count+1) else: return "提问太快啦,请休息一下再问我吧" + except openai.error.APIConnectionError as e: + # api connection exception + logger.warn(e) + logger.warn("[OPEN_AI] APIConnection failed") + return "我连接不到你的网络" + except openai.error.Timeout as e: + logger.warn(e) + logger.warn("[OPEN_AI] Timeout") + return "我没有收到你的消息" except Exception as e: # unknown exception logger.exception(e)