From 72638fac683575b20f2dc55bc17374b821622552 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Tue, 23 May 2023 07:58:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DQQ=E9=A2=91=E9=81=93@?= =?UTF-8?q?=E4=B8=8D=E5=9B=9E=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 12 ++++++++++-- model/provider/provider_openai_official.py | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index 8625389c9..f7fafd7d9 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -512,8 +512,16 @@ def oper_msg(message, if isinstance(i, Plain): qq_msg += str(i.text).strip() if isinstance(i, At): - if i.qq == message.self_id: - with_tag = True + # @机器人 + if message.type == "GuildMessage": + if i.qq == message.self_tiny_id: + with_tag = True + if message.type == "FriendMessage": + if i.qq == message.self_id: + with_tag = True + if message.type == "GroupMessage": + if i.qq == message.self_id: + with_tag = True for i in nick_qq: if i != '' and qq_msg.startswith(i): diff --git a/model/provider/provider_openai_official.py b/model/provider/provider_openai_official.py index 462f61f53..01e099fb3 100644 --- a/model/provider/provider_openai_official.py +++ b/model/provider/provider_openai_official.py @@ -112,6 +112,7 @@ class ProviderOpenAIOfficial(Provider): cache_data_list, new_record, req = self.wrap(prompt, session_id) retry = 0 response = None + err = '' while retry < 5: try: response = openai.ChatCompletion.create( @@ -121,7 +122,7 @@ class ProviderOpenAIOfficial(Provider): break except Exception as e: if 'You exceeded' in str(e) or 'Billing hard limit has been reached' in str(e) or 'No API key provided' in str(e) or 'Incorrect API key provided' in str(e): - gu.log("当前Key已超额或者不正常,正在切换", level=gu.LEVEL_WARNING) + gu.log("当前Key已超额或异常, 正在切换", level=gu.LEVEL_WARNING) self.key_stat[openai.api_key]['exceed'] = True self.save_key_record() @@ -137,10 +138,11 @@ class ProviderOpenAIOfficial(Provider): cache_data_list, new_record, req = self.wrap(prompt, session_id) else: gu.log(str(e), level=gu.LEVEL_ERROR) + err = str(e) retry+=1 if retry >= 5: gu.log(r"如果报错, 且您的机器在中国大陆内, 请确保您的电脑已经设置好代理软件(梯子), 并在配置文件设置了系统代理地址。详见https://github.com/Soulter/QQChannelChatGPT/wiki/%E4%BA%8C%E3%80%81%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E9%85%8D%E7%BD%AE", max_len=999) - raise BaseException("连接出错") + raise BaseException("连接出错: "+str(err)) self.key_stat[openai.api_key]['used'] += response['usage']['total_tokens'] self.save_key_record()