From 0773490c77e40e0e3f2e592d5d455f54e8cd0343 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 9 Feb 2023 14:33:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?perf:=20The=20server=20had=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=97=B6=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/message.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/qqbot/message.py b/pkg/qqbot/message.py index 05e0d6f1..3724b669 100644 --- a/pkg/qqbot/message.py +++ b/pkg/qqbot/message.py @@ -29,8 +29,15 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, session = pkg.openai.session.get_session(session_name) + unexpected_exception_times = 0 + + max_unexpected_exception_times = 3 + reply = [] while True: + if unexpected_exception_times >= max_unexpected_exception_times: + reply = handle_exception(notify_admin=f"[bot]{session_name},多次尝试失败。", set_reply=f"[bot]多次尝试失败,请重试或联系管理员") + break try: prefix = "[GPT]" if hasattr(config, "show_prefix") and config.show_prefix else "" @@ -92,6 +99,12 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, continue elif 'message' in e.error and e.error['message'].__contains__('You can retry your request'): # 重试 + unexpected_exception_times += 1 + continue + elif 'message' in e.error and e.error['message']\ + .__contains__('The server had an error while processing your request'): + # 重试 + unexpected_exception_times += 1 continue else: reply = handle_exception("{}会话调用API失败:{}".format(session_name, e), From 8b2128b4dc2766c14118b391c466ca4089ec9bea Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 9 Feb 2023 15:05:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?perf:=20=E5=BC=82=E5=B8=B8=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/message.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/qqbot/message.py b/pkg/qqbot/message.py index 3724b669..62c13887 100644 --- a/pkg/qqbot/message.py +++ b/pkg/qqbot/message.py @@ -64,7 +64,12 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, if not event.is_prevented_default(): reply = [prefix + text] except openai.error.APIConnectionError as e: - reply = handle_exception("{}会话调用API失败:{}".format(session_name, e), "[bot]err:调用API失败,请重试或联系作者,或等待修复") + err_msg = str(e) + if err_msg.__contains__('Error communicating with OpenAI'): + reply = handle_exception("{}会话调用API失败:{}\n请尝试关闭网络代理来解决此问题。".format(session_name, e), + "[bot]err:调用API失败,请重试或联系管理员,或等待修复") + else: + reply = handle_exception("{}会话调用API失败:{}".format(session_name, e), "[bot]err:调用API失败,请重试或联系管理员,或等待修复") except openai.error.RateLimitError as e: logging.debug(type(e)) logging.debug(e.error['message']) @@ -90,8 +95,8 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, if not switched: reply = handle_exception( - "api-key调用额度超限({}),无可用api_key,请向OpenAI账户充值或在config.py中更换api_key".format( - current_key_name), "[bot]err:API调用额度超额,请联系作者,或等待修复") + "api-key调用额度超限({}),无可用api_key,请向OpenAI账户充值或在config.py中更换api_key;如果你认为这是误判,请尝试重启程序。".format( + current_key_name), "[bot]err:API调用额度超额,请联系管理员,或等待修复") else: openai.api_key = pkg.utils.context.get_openai_manager().key_mgr.get_using_key() mgr.notify_admin("api-key调用额度超限({}),接口报错,已切换到{}".format(current_key_name, name)) @@ -112,9 +117,9 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, except openai.error.InvalidRequestError as e: reply = handle_exception("{}API调用参数错误:{}\n\n这可能是由于config.py中的prompt_submit_length参数或" "completion_api_params中的max_tokens参数数值过大导致的,请尝试将其降低".format( - session_name, e), "[bot]err:API调用参数错误,请联系作者,或等待修复") + session_name, e), "[bot]err:API调用参数错误,请联系管理员,或等待修复") except openai.error.ServiceUnavailableError as e: - reply = handle_exception("{}API调用服务不可用:{}".format(session_name, e), "[bot]err:API调用服务不可用,请重试或联系作者,或等待修复") + reply = handle_exception("{}API调用服务不可用:{}".format(session_name, e), "[bot]err:API调用服务不可用,请重试或联系管理员,或等待修复") except Exception as e: logging.exception(e) reply = handle_exception("{}会话处理异常:{}".format(session_name, e), "[bot]err:{}".format(e)) From d3a6928e3afed7687b2873fb34e2178f8ddc17e3 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 9 Feb 2023 15:06:47 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E5=BC=82=E5=B8=B8=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=BD=99=E7=9A=84[bot]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/qqbot/message.py b/pkg/qqbot/message.py index 62c13887..2b2cc6c2 100644 --- a/pkg/qqbot/message.py +++ b/pkg/qqbot/message.py @@ -36,7 +36,7 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, reply = [] while True: if unexpected_exception_times >= max_unexpected_exception_times: - reply = handle_exception(notify_admin=f"[bot]{session_name},多次尝试失败。", set_reply=f"[bot]多次尝试失败,请重试或联系管理员") + reply = handle_exception(notify_admin=f"{session_name},多次尝试失败。", set_reply=f"[bot]多次尝试失败,请重试或联系管理员") break try: prefix = "[GPT]" if hasattr(config, "show_prefix") and config.show_prefix else ""