fix(qqbot): 超额误判问题 (#106)

This commit is contained in:
Rock Chin 2023-01-25 22:51:09 +08:00
parent 057d8a05d7
commit 99282100a0
2 changed files with 33 additions and 27 deletions

View File

@ -262,8 +262,8 @@ class QQBotManager:
except FunctionTimedOut: except FunctionTimedOut:
logging.warning("group_{}: 超时,重试中({})".format(event.group.id, i)) logging.warning("group_{}: 超时,重试中({})".format(event.group.id, i))
pkg.openai.session.get_session('group_{}'.format(event.group.id)).release_response_lock() pkg.openai.session.get_session('group_{}'.format(event.group.id)).release_response_lock()
if "group_{}".format(event.sender.id) in pkg.qqbot.process.processing: if "group_{}".format(event.group.id) in pkg.qqbot.process.processing:
pkg.qqbot.process.processing.remove('group_{}'.format(event.sender.id)) pkg.qqbot.process.processing.remove('group_{}'.format(event.group.id))
failed += 1 failed += 1
continue continue

View File

@ -48,6 +48,9 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str,
reply = ["[bot]err:调用API失败请重试或联系作者或等待修复"] reply = ["[bot]err:调用API失败请重试或联系作者或等待修复"]
except openai.error.RateLimitError as e: except openai.error.RateLimitError as e:
logging.debug(type(e)) logging.debug(type(e))
logging.debug(e.error['message'])
if 'message' in e.error and e.error['message'].__contains__('You exceeded your current quota'):
# 尝试切换api-key # 尝试切换api-key
current_key_name = pkg.utils.context.get_openai_manager().key_mgr.get_key_name( current_key_name = pkg.utils.context.get_openai_manager().key_mgr.get_key_name(
pkg.utils.context.get_openai_manager().key_mgr.using_key pkg.utils.context.get_openai_manager().key_mgr.using_key
@ -76,6 +79,9 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str,
mgr.notify_admin("api-key调用额度超限({}),接口报错,已切换到{}".format(current_key_name, name)) mgr.notify_admin("api-key调用额度超限({}),接口报错,已切换到{}".format(current_key_name, name))
reply = ["[bot]err:API调用额度超额已自动切换请重新发送消息"] reply = ["[bot]err:API调用额度超额已自动切换请重新发送消息"]
continue continue
else:
mgr.notify_admin("{}会话调用API失败:{}".format(session_name, e))
reply = ["[bot]err:RateLimitError,请重试或联系作者,或等待修复"]
except openai.error.InvalidRequestError as e: except openai.error.InvalidRequestError as e:
mgr.notify_admin("{}API调用参数错误:{}\n\n这可能是由于config.py中的prompt_submit_length参数或" mgr.notify_admin("{}API调用参数错误:{}\n\n这可能是由于config.py中的prompt_submit_length参数或"
"completion_api_params中的max_tokens参数数值过大导致的请尝试将其降低".format( "completion_api_params中的max_tokens参数数值过大导致的请尝试将其降低".format(