From 2f2159239a013c99404ce8d53aafb17ee496d75e Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 8 Jun 2023 13:20:33 +0800 Subject: [PATCH 1/5] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E5=92=8C=E6=8F=90=E7=A4=BA=E8=AF=AD=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 4 ++++ tips-custom-template.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/config-template.py b/config-template.py index 2588ca35..401526ee 100644 --- a/config-template.py +++ b/config-template.py @@ -195,6 +195,10 @@ encourage_sponsor_at_start = True # 注意:较大的prompt_submit_length会导致OpenAI账户额度消耗更快 prompt_submit_length = 2048 +# 是否在token超限报错时自动重置会话 +# 可在tips.py中编辑提示语 +auto_reset = True + # OpenAI补全API的参数 # 请在下方填写模型,程序自动选择接口 # 现已支持的模型有: diff --git a/tips-custom-template.py b/tips-custom-template.py index 09eb7f19..16740b97 100644 --- a/tips-custom-template.py +++ b/tips-custom-template.py @@ -32,3 +32,6 @@ command_err_message = "[bot]err:指令不存在:" # 会话重置提示 command_reset_message = "[bot]:会话已重置" command_reset_name_message = "[bot]:会话已重置,使用场景预设:" + +# 会话自动重置时的提示 +session_auto_reset_message = "[bot]:会话token超限,已自动重置" From b6da07b22522d4969dc627673bb04adf484e2f40 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 8 Jun 2023 05:20:55 +0000 Subject: [PATCH 2/5] Update override-all.json --- override-all.json | 1 + 1 file changed, 1 insertion(+) diff --git a/override-all.json b/override-all.json index 298f9b61..eafbbd5e 100644 --- a/override-all.json +++ b/override-all.json @@ -53,6 +53,7 @@ "inappropriate_message_tips": "[百度云]请珍惜机器人,当前返回内容不合规", "encourage_sponsor_at_start": true, "prompt_submit_length": 2048, + "auto_reset": true, "completion_api_params": { "model": "gpt-3.5-turbo", "temperature": 0.9, From 466bfbddebd17fb1fa87b2b69a72ceaceb0ad962 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 8 Jun 2023 13:43:33 +0800 Subject: [PATCH 3/5] =?UTF-8?q?perf:=20=E6=8F=90=E7=A4=BA=E8=AF=AD?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tips-custom-template.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tips-custom-template.py b/tips-custom-template.py index 16740b97..49380845 100644 --- a/tips-custom-template.py +++ b/tips-custom-template.py @@ -30,8 +30,8 @@ command_admin_message = "[bot]err:权限不足: " command_err_message = "[bot]err:指令不存在:" # 会话重置提示 -command_reset_message = "[bot]:会话已重置" -command_reset_name_message = "[bot]:会话已重置,使用场景预设:" +command_reset_message = "[bot]会话已重置" +command_reset_name_message = "[bot]会话已重置,使用场景预设:" # 会话自动重置时的提示 -session_auto_reset_message = "[bot]:会话token超限,已自动重置" +session_auto_reset_message = "[bot]会话token超限,已自动重置" From 43aa68a55d2f4ce094d42efd669a2991f9e8ecee Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 8 Jun 2023 13:45:54 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=9C=A8token?= =?UTF-8?q?=E8=B6=85=E9=99=90=E6=97=B6=E8=87=AA=E5=8A=A8=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/openai/session.py | 2 +- pkg/qqbot/message.py | 8 ++++++-- pkg/qqbot/process.py | 2 +- tips-custom-template.py | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/openai/session.py b/pkg/openai/session.py index 4a74e971..fc217ab3 100644 --- a/pkg/openai/session.py +++ b/pkg/openai/session.py @@ -83,7 +83,7 @@ def load_sessions(): # 获取指定名称的session,如果不存在则创建一个新的 -def get_session(session_name: str): +def get_session(session_name: str) -> 'Session': global sessions if session_name not in sessions: sessions[session_name] = Session(session_name) diff --git a/pkg/qqbot/message.py b/pkg/qqbot/message.py index 4fb6b991..68715922 100644 --- a/pkg/qqbot/message.py +++ b/pkg/qqbot/message.py @@ -114,8 +114,12 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, reply = handle_exception("{}会话调用API失败:{}".format(session_name, e), "[bot]err:RateLimitError,请重试或联系作者,或等待修复") except openai.error.InvalidRequestError as e: - reply = handle_exception("{}API调用参数错误:{}\n".format( - session_name, e), "[bot]err:API调用参数错误,请联系管理员,或等待修复") + if config.auto_reset: + session.reset() + reply = [tips_custom.session_auto_reset_message] + else: + reply = handle_exception("{}API调用参数错误:{}\n".format( + session_name, e), "[bot]err:API调用参数错误,请联系管理员,或等待修复") except openai.error.ServiceUnavailableError as e: reply = handle_exception("{}API调用服务不可用:{}".format(session_name, e), "[bot]err:API调用服务不可用,请重试或联系管理员,或等待修复") except Exception as e: diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 5af3c084..3ae95437 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -74,7 +74,7 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes import config if config.income_msg_check: if mgr.reply_filter.is_illegal(text_message): - return MessageChain(Plain("[bot] 你的提问中有不合适的内容, 请更换措辞~")) + return MessageChain(Plain("[bot] 消息中存在不合适的内容, 请更换措辞")) pkg.openai.session.get_session(session_name).acquire_response_lock() diff --git a/tips-custom-template.py b/tips-custom-template.py index 49380845..639751d2 100644 --- a/tips-custom-template.py +++ b/tips-custom-template.py @@ -34,4 +34,4 @@ command_reset_message = "[bot]会话已重置" command_reset_name_message = "[bot]会话已重置,使用场景预设:" # 会话自动重置时的提示 -session_auto_reset_message = "[bot]会话token超限,已自动重置" +session_auto_reset_message = "[bot]会话token超限,已自动重置,请重新发送消息" From 9e78bf3d218f9e6fc1f548439aa16e316a9fe07e Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 8 Jun 2023 13:49:20 +0800 Subject: [PATCH 5/5] =?UTF-8?q?perf:=20=E6=9B=B4=E4=B8=A5=E6=A0=BC?= =?UTF-8?q?=E7=9A=84=E9=87=8D=E7=BD=AE=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= 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 68715922..4c0207df 100644 --- a/pkg/qqbot/message.py +++ b/pkg/qqbot/message.py @@ -114,7 +114,7 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str, reply = handle_exception("{}会话调用API失败:{}".format(session_name, e), "[bot]err:RateLimitError,请重试或联系作者,或等待修复") except openai.error.InvalidRequestError as e: - if config.auto_reset: + if config.auto_reset and "This model's maximum context length is" in str(e): session.reset() reply = [tips_custom.session_auto_reset_message] else: