From fb7669ddadb6b8c6dc2d4c226d72a55733dbbe68 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 1 Oct 2023 16:20:51 +0800 Subject: [PATCH 1/5] =?UTF-8?q?perf:=20=E4=BE=9D=E8=B5=96=E5=BA=93?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index 8252213a8..8d474a21a 100644 --- a/main.py +++ b/main.py @@ -48,7 +48,7 @@ def privider_chooser(cfg): l.append('openai_official') return l -def check_env(): +def check_env(ch_mirror=False): if not (sys.version_info.major == 3 and sys.version_info.minor >= 8): print("请使用Python3.8运行本项目") input("按任意键退出...") @@ -60,7 +60,11 @@ def check_env(): pth = 'QQChannelChatGPT'+ os.sep +'requirements.txt' print("正在检查更新第三方库...") try: - pipmain(['install', '-r', pth, '--quiet']) + if ch_mirror: + print("使用阿里云镜像") + pipmain(['install', '-r', pth, '-i', 'https://mirrors.aliyun.com/pypi/simple/', '--quiet']) + else: + pipmain(['install', '-r', pth, '--quiet']) except BaseException as e: print(e) while True: @@ -96,17 +100,20 @@ def get_platform(): print("other") if __name__ == "__main__": - check_env() - # 获取参数 args = sys.argv - if len(args) > 1: - if args[1] == '-replit': - print("[System] 启动Replit Web保活服务...") - try: - from webapp_replit import keep_alive - keep_alive() - except BaseException as e: - print(e) - print(f"[System-err] Replit Web保活服务启动失败:{str(e)}") + + if '-cn' in args: + check_env(True) + else: + check_env() + + if '-replit' in args: + print("[System] 启动Replit Web保活服务...") + try: + from webapp_replit import keep_alive + keep_alive() + except BaseException as e: + print(e) + print(f"[System-err] Replit Web保活服务启动失败:{str(e)}") main() From 6acd7be5471c8f6f1ed1a25c4b4b9c06dc52cbdd Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 1 Oct 2023 17:46:51 +0800 Subject: [PATCH 2/5] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=BA=93=E7=9A=84=E5=AF=BC=E5=85=A5=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 6 +++--- model/command/command.py | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index e9fe70fdc..73ad2474a 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -25,9 +25,6 @@ from nakuru import ( from nakuru.entities.components import Plain,At,Image from model.provider.provider import Provider from model.command.command import Command -from model.command.command_rev_chatgpt import CommandRevChatGPT -from model.command.command_rev_edgegpt import CommandRevEdgeGPT -from model.command.command_openai_official import CommandOpenAIOfficial from util import general_utils as gu from util.cmd_config import CmdConfig as cc import util.gplugin as gplugin @@ -235,6 +232,7 @@ def initBot(cfg, prov): if cfg['rev_ChatGPT']['enable']: if 'account' in cfg['rev_ChatGPT']: from model.provider.provider_rev_chatgpt import ProviderRevChatGPT + from model.command.command_rev_chatgpt import CommandRevChatGPT llm_instance[REV_CHATGPT] = ProviderRevChatGPT(cfg['rev_ChatGPT'], base_url=cc.get("CHATGPT_BASE_URL", None)) llm_command_instance[REV_CHATGPT] = CommandRevChatGPT(llm_instance[REV_CHATGPT], _global_object) chosen_provider = REV_CHATGPT @@ -249,6 +247,7 @@ def initBot(cfg, prov): if cfg['rev_edgegpt']['enable']: try: from model.provider.provider_rev_edgegpt import ProviderRevEdgeGPT + from model.command.command_rev_edgegpt import CommandRevEdgeGPT llm_instance[REV_EDGEGPT] = ProviderRevEdgeGPT() llm_command_instance[REV_EDGEGPT] = CommandRevEdgeGPT(llm_instance[REV_EDGEGPT], _global_object) chosen_provider = REV_EDGEGPT @@ -258,6 +257,7 @@ def initBot(cfg, prov): gu.log("- OpenAI官方 -", gu.LEVEL_INFO) if cfg['openai']['key'] is not None: from model.provider.provider_openai_official import ProviderOpenAIOfficial + from model.command.command_openai_official import CommandOpenAIOfficial llm_instance[OPENAI_OFFICIAL] = ProviderOpenAIOfficial(cfg['openai']) llm_command_instance[OPENAI_OFFICIAL] = CommandOpenAIOfficial(llm_instance[OPENAI_OFFICIAL], _global_object) chosen_provider = OPENAI_OFFICIAL diff --git a/model/command/command.py b/model/command/command.py index 7a06f8d8f..67441b751 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -1,6 +1,13 @@ import json -import git.exc -from git.repo import Repo + +has_git = True +try: + import git.exc + from git.repo import Repo +except BaseException as e: + print("你正在运行在无Git环境下,暂时将无法使用插件、热更新功能。") + has_git = False + import os import sys import requests @@ -142,6 +149,8 @@ class Command: 插件指令 ''' def plugin_oper(self, message: str, role: str, cached_plugins: dict, platform: str): + if not has_git: + return False, "你正在运行在无Git环境下,暂时将无法使用插件、热更新功能。", "plugin" l = message.split(" ") if len(l) < 2: p = gu.create_text_image("【插件指令面板】", "安装插件: \nplugin i 插件Github地址\n卸载插件: \nplugin d 插件名 \n重载插件: \nplugin reload\n查看插件列表:\nplugin l\n更新插件: plugin u 插件名\n") @@ -418,6 +427,8 @@ class Command: return False, "设置失败: "+str(e), "keyword" def update(self, message: str, role: str): + if not has_git: + return False, "你正在运行在无Git环境下,暂时将无法使用插件、热更新功能。", "update" if role != "admin": return True, "你没有权限使用该指令", "keyword" l = message.split(" ") From aa3262a8ab61363fdeecef0800f8146a8ba189e5 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 2 Oct 2023 10:10:04 +0800 Subject: [PATCH 3/5] chore: fix some typos --- main.py | 4 ++-- model/command/command.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 8d474a21a..f8320873d 100644 --- a/main.py +++ b/main.py @@ -49,8 +49,8 @@ def privider_chooser(cfg): return l def check_env(ch_mirror=False): - if not (sys.version_info.major == 3 and sys.version_info.minor >= 8): - print("请使用Python3.8运行本项目") + if not (sys.version_info.major == 3 and sys.version_info.minor >= 9): + print("请使用Python3.9+运行本项目") input("按任意键退出...") exit() diff --git a/model/command/command.py b/model/command/command.py index 67441b751..29083c5e2 100644 --- a/model/command/command.py +++ b/model/command/command.py @@ -5,7 +5,7 @@ try: import git.exc from git.repo import Repo except BaseException as e: - print("你正在运行在无Git环境下,暂时将无法使用插件、热更新功能。") + print("你正运行在无Git环境下,暂时将无法使用插件、热更新功能。") has_git = False import os From 3198f73f3d242dd3d194123b95dd18a45f377242 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 2 Oct 2023 10:17:10 +0800 Subject: [PATCH 4/5] =?UTF-8?q?perf:=20=E6=B8=85=E9=99=A4=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=EF=BC=9B=E9=80=82=E9=85=8D=E6=96=B0=E7=89=88=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index f8320873d..8f0a1b25e 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,10 @@ import os, sys from pip._internal import main as pipmain +import warnings +warnings.filterwarnings("ignore") abs_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '/' +os.chdir(abs_path) def main(): try: From 3424b658f3d502d0530d206ddc6e44902305cd6f Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 2 Oct 2023 10:35:51 +0800 Subject: [PATCH 5/5] bugfixes --- main.py | 1 - model/provider/provider_openai_official.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index 8f0a1b25e..3a1312637 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,6 @@ import warnings warnings.filterwarnings("ignore") abs_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '/' -os.chdir(abs_path) def main(): try: diff --git a/model/provider/provider_openai_official.py b/model/provider/provider_openai_official.py index 625e9529c..92e953903 100644 --- a/model/provider/provider_openai_official.py +++ b/model/provider/provider_openai_official.py @@ -9,7 +9,7 @@ import threading from util import general_utils as gu abs_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '/' -key_record_path = abs_path+'chatgpt_key_record' +key_record_path = abs_path + 'chatgpt_key_record' class ProviderOpenAIOfficial(Provider): def __init__(self, cfg):