From d784e7e00aaae243372e7dd99180302d593e63b8 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 14 Jun 2023 21:40:08 +0800 Subject: [PATCH] close auto load plugin --- pilot/common/plugins.py | 50 ++++++++++++++++++++++++----------------- pilot/configs/config.py | 2 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/pilot/common/plugins.py b/pilot/common/plugins.py index 2a142d513..49c79c4d6 100644 --- a/pilot/common/plugins.py +++ b/pilot/common/plugins.py @@ -5,6 +5,7 @@ import os import glob import zipfile import requests +import threading import datetime from pathlib import Path from typing import List @@ -77,28 +78,35 @@ def load_native_plugins(cfg: Config): if not cfg.plugins_auto_load: print("not auto load_native_plugins") return - print("load_native_plugins") - ### TODO 默认拉主分支,后续拉发布版本 - branch_name = cfg.plugins_git_branch - native_plugin_repo ="DB-GPT-Plugins" - url = "https://github.com/csunny/{repo}/archive/{branch}.zip" - response = requests.get(url.format(repo=native_plugin_repo, branch=branch_name), - headers={'Authorization': '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'}) + def load_from_git(cfg: Config): + print("load_native_plugins") + ### TODO 默认拉主分支,后续拉发布版本 + branch_name = cfg.plugins_git_branch + native_plugin_repo = "DB-GPT-Plugins" + url = "https://github.com/csunny/{repo}/archive/{branch}.zip" + response = requests.get(url.format(repo=native_plugin_repo, branch=branch_name), + headers={'Authorization': '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'}) - if response.status_code == 200: - plugins_path_path = Path(PLUGINS_DIR) - files = glob.glob(os.path.join(plugins_path_path, f'{native_plugin_repo}*')) - for file in files: - os.remove(file) - now = datetime.datetime.now() - time_str = now.strftime('%Y%m%d%H%M%S') - file_name = f"{plugins_path_path}/{native_plugin_repo}-{branch_name}-{time_str}.zip" - print(file_name) - with open(file_name, "wb") as f: - f.write(response.content) - print("文件已保存到本地") - else: - print("获取Release信息失败,状态码为:", response.status_code) + if response.status_code == 200: + plugins_path_path = Path(PLUGINS_DIR) + files = glob.glob(os.path.join(plugins_path_path, f'{native_plugin_repo}*')) + for file in files: + os.remove(file) + now = datetime.datetime.now() + time_str = now.strftime('%Y%m%d%H%M%S') + file_name = f"{plugins_path_path}/{native_plugin_repo}-{branch_name}-{time_str}.zip" + print(file_name) + with open(file_name, "wb") as f: + f.write(response.content) + print("文件已保存到本地") + cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode)) + else: + print("获取Release信息失败,状态码为:", response.status_code) + + # 创建一个线程 + t = threading.Thread(target=load_from_git, args=(cfg,)) + # 启动线程 + t.start() def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate]: diff --git a/pilot/configs/config.py b/pilot/configs/config.py index d4ed13f22..6db040a9d 100644 --- a/pilot/configs/config.py +++ b/pilot/configs/config.py @@ -90,7 +90,7 @@ class Config(metaclass=Singleton): ### The associated configuration parameters of the plug-in control the loading and use of the plug-in self.plugins: List[AutoGPTPluginTemplate] = [] self.plugins_openai = [] - self.plugins_auto_load = os.getenv("AUTO_LOAD_PLUGIN", "False") == "True" + self.plugins_auto_load = os.getenv("AUTO_LOAD_PLUGIN", "True") == "True" self.plugins_git_branch = os.getenv("PLUGINS_GIT_BRANCH", "plugin_dashboard")