perf: 优化一些库的导入机制

This commit is contained in:
Soulter
2023-10-01 17:46:51 +08:00
parent fb7669ddad
commit 6acd7be547
2 changed files with 16 additions and 5 deletions
+3 -3
View File
@@ -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
+13 -2
View File
@@ -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(" ")