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] =?UTF-8?q?perf:=20=E5=BC=82=E5=B8=B8=E8=BE=93=E5=87=BA?= =?UTF-8?q?=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))