Browse Source

Merge pull request #349 from sunxin18/add_more_exception

[feat] catch connection failed exception
develop
zhayujie GitHub 1 year ago
parent
commit
fb598fba82
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions
  1. +9
    -0
      bot/chatgpt/chat_gpt_bot.py

+ 9
- 0
bot/chatgpt/chat_gpt_bot.py View File

@@ -63,6 +63,15 @@ class ChatGPTBot(Bot):
return self.reply_text(query, user_id, retry_count+1) return self.reply_text(query, user_id, retry_count+1)
else: else:
return "提问太快啦,请休息一下再问我吧" 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: except Exception as e:
# unknown exception # unknown exception
logger.exception(e) logger.exception(e)


Loading…
Cancel
Save