From 8506cdae8fc60249ecfe73250673ce6a697a3226 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sat, 7 Jan 2023 23:24:13 +0800 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=E9=BB=98=E8=AE=A4=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=97=B6=E9=97=B4=E4=BF=AE=E6=94=B9=E4=B8=BA30s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-template.py b/config-template.py index 67bb5ae..89cead8 100644 --- a/config-template.py +++ b/config-template.py @@ -97,7 +97,7 @@ quote_origin = True include_image_description = True # 消息处理的超时时间,单位为秒 -process_message_timeout = 15 +process_message_timeout = 30 # 机器人的配置 # user_name: 管理员(主人)的名字 From 2dcbe8798647ec8ddd1f7b29909c41337cc8d0c5 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sat, 7 Jan 2023 23:26:22 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=E5=87=BD=E6=95=B0=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=97=B6=E6=8E=A7=E5=88=B6=E5=8F=B0=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/qqbot/manager.py b/pkg/qqbot/manager.py index 1df3673..b8c66fd 100644 --- a/pkg/qqbot/manager.py +++ b/pkg/qqbot/manager.py @@ -159,6 +159,7 @@ class QQBotManager: event.sender.id) break except FunctionTimedOut: + logging.warning("person_{}: 超时,重试中".format(event.sender.id)) pkg.openai.session.get_session('person_{}'.format(event.sender.id)).release_response_lock() failed += 1 continue @@ -191,6 +192,7 @@ class QQBotManager: event.sender.id) break except FunctionTimedOut: + logging.warning("group_{}: 超时,重试中".format(event.group.id)) pkg.openai.session.get_session('group_{}'.format(event.group.id)).release_response_lock() failed += 1 continue From 06264354cfb5507626230a54b1deb21bde34420a Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sun, 8 Jan 2023 14:49:23 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E8=B6=85=E6=97=B6=E4=B8=8D=E9=87=8D?= =?UTF-8?q?=E8=AF=95=E7=9A=84=E9=97=AE=E9=A2=98=20(#91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/manager.py | 4 +++- pkg/qqbot/process.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/qqbot/manager.py b/pkg/qqbot/manager.py index b8c66fd..9e7de95 100644 --- a/pkg/qqbot/manager.py +++ b/pkg/qqbot/manager.py @@ -159,8 +159,10 @@ class QQBotManager: event.sender.id) break except FunctionTimedOut: - logging.warning("person_{}: 超时,重试中".format(event.sender.id)) + logging.warning("person_{}: 超时".format(event.sender.id)) pkg.openai.session.get_session('person_{}'.format(event.sender.id)).release_response_lock() + if "person_{}".format(event.sender.id) in pkg.qqbot.process.processing: + pkg.qqbot.process.processing.remove('person_{}'.format(event.sender.id)) failed += 1 continue diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index 0fbfd00..f5cb251 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -8,7 +8,7 @@ from func_timeout import func_set_timeout import logging import openai -from mirai import Image, MessageChain +from mirai import Image, MessageChain, Plain # 这里不使用动态引入config # 因为在这里动态引入会卡死程序 @@ -114,7 +114,7 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes try: if session_name in processing: pkg.openai.session.get_session(session_name).release_response_lock() - return ["[bot]err:正在处理中,请稍后再试"] + return MessageChain([Plain("[bot]err:正在处理中,请稍后再试")]) processing.append(session_name) From c662e2c4e3d849e15cf8876c90548bbcb0782b44 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sun, 8 Jan 2023 16:32:27 +0800 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20url=E8=BF=87=E9=95=BF=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E4=B8=8A=E6=8A=A5=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/audit/gatherer.py | 3 ++- pkg/utils/updater.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/audit/gatherer.py b/pkg/audit/gatherer.py index 34e7054..9ec9581 100644 --- a/pkg/audit/gatherer.py +++ b/pkg/audit/gatherer.py @@ -25,7 +25,7 @@ class DataGatherer: def __init__(self): self.load_from_db() try: - self.version_str = pkg.utils.updater.get_commit_id_and_time_and_msg()[:50 if len(pkg.utils.updater.get_commit_id_and_time_and_msg()) > 50 else len(pkg.utils.updater.get_commit_id_and_time_and_msg())] + self.version_str = pkg.utils.updater.get_commit_id_and_time_and_msg()[:40 if len(pkg.utils.updater.get_commit_id_and_time_and_msg()) > 40 else len(pkg.utils.updater.get_commit_id_and_time_and_msg())] except: pass @@ -34,6 +34,7 @@ class DataGatherer: config = pkg.utils.context.get_config() if hasattr(config, "report_usage") and not config.report_usage: return + print("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, self.version_str, count)) res = requests.get("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, self.version_str, count)) if res.status_code != 200 or res.text != "ok": logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text)) diff --git a/pkg/utils/updater.py b/pkg/utils/updater.py index 8b832eb..3dedc23 100644 --- a/pkg/utils/updater.py +++ b/pkg/utils/updater.py @@ -52,7 +52,7 @@ def get_current_version_info() -> str: version_str += "提交编号: "+str(entry.commit.id)[2:9] + "\n" tz = datetime.timezone(datetime.timedelta(hours=entry.commit.commit_timezone // 3600)) dt = datetime.datetime.fromtimestamp(entry.commit.commit_time, tz) - version_str += "时间: "+dt.strftime('%Y-%m-%d %H:%M:%S') + "\n" + version_str += "时间: "+dt.strftime('%m-%d %H:%M:%S') + "\n" version_str += "说明: "+str(entry.commit.message, encoding="utf-8").strip() + "\n" version_str += "提交作者: '" + str(entry.commit.author)[2:-1] + "'" break From 5256d3c718b48e60dc80e291adc17eafe8e55346 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sun, 8 Jan 2023 16:33:33 +0800 Subject: [PATCH 5/6] =?UTF-8?q?debug:=20=E5=88=A0=E9=99=A4=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/audit/gatherer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/audit/gatherer.py b/pkg/audit/gatherer.py index 9ec9581..4d9738d 100644 --- a/pkg/audit/gatherer.py +++ b/pkg/audit/gatherer.py @@ -34,7 +34,7 @@ class DataGatherer: config = pkg.utils.context.get_config() if hasattr(config, "report_usage") and not config.report_usage: return - print("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, self.version_str, count)) + # print("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, self.version_str, count)) res = requests.get("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, self.version_str, count)) if res.status_code != 200 or res.text != "ok": logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text)) From 9d31d8b071b421977aadd5eacda17a150c27713c Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sun, 8 Jan 2023 20:43:37 +0800 Subject: [PATCH 6/6] =?UTF-8?q?perf:=20=E8=B6=85=E9=A2=9D=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/process.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index f5cb251..aee1d4f 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -307,18 +307,19 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes reply = ["[bot]err:调用API失败,请重试或联系作者,或等待修复"] except openai.error.RateLimitError as e: # 尝试切换api-key - current_tokens_amt = pkg.utils.context.get_openai_manager().key_mgr.get_fee( - pkg.utils.context.get_openai_manager().key_mgr.get_using_key()) + 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.set_current_exceeded() switched, name = pkg.utils.context.get_openai_manager().key_mgr.auto_switch() if not switched: - mgr.notify_admin("API调用额度超限({}),无可用api_key,请向OpenAI账户充值或在config.py中更换api_key".format( - current_tokens_amt)) + mgr.notify_admin("api-key调用额度超限({}),无可用api_key,请向OpenAI账户充值或在config.py中更换api_key".format( + current_key_name)) reply = ["[bot]err:API调用额度超额,请联系作者,或等待修复"] else: openai.api_key = pkg.utils.context.get_openai_manager().key_mgr.get_using_key() - mgr.notify_admin("API调用额度超限({}),接口报错,已切换到{}".format(current_tokens_amt, name)) + mgr.notify_admin("api-key调用额度超限({}),接口报错,已切换到{}".format(current_key_name, name)) reply = ["[bot]err:API调用额度超额,已自动切换,请重新发送消息"] continue except openai.error.InvalidRequestError as e: