feat: 回复消息引用 #28

perf: 完善逆向库中RateLimit的切换机制
perf: 其他优化
This commit is contained in:
Soulter
2023-03-06 23:23:44 +08:00
parent c0e4d0595b
commit 09cfd18f6f
2 changed files with 65 additions and 24 deletions
+27 -7
View File
@@ -1,4 +1,4 @@
from revChatGPT.V1 import Chatbot
from revChatGPT.V1 import Chatbot, Error
class revChatGPT:
def __init__(self, config):
@@ -10,6 +10,20 @@ class revChatGPT:
def chat(self, prompt):
resp = ''
"""
Base class for exceptions in this module.
Error codes:
-1: User error
0: Unknown error
1: Server error
2: Rate limit error
3: Invalid request error
4: Expired access token error
5: Invalid access token error
6: Prohibited concurrent query error
"""
err_count = 0
retry_count = 5
@@ -18,12 +32,18 @@ class revChatGPT:
for data in self.chatbot.ask(prompt):
resp = data["message"]
break
except BaseException as e:
print(e)
print("[RevChatGPT] 请求出现了一些问题, 正在重试。次数"+str(err_count))
err_count += 1
if err_count == retry_count:
raise e
except Error as e:
try:
if e.code == 2:
print("[RevChatGPT] 频率限制")
raise e
else:
print("[RevChatGPT] 请求出现了一些问题, 正在重试。次数"+str(err_count))
err_count += 1
if err_count >= retry_count:
raise e
except BaseException:
err_count += 1
print("[RevChatGPT] "+str(resp))
return resp