From 9b8adc5d6cf54ecf60ea427994b0ddb7067ef31c Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Tue, 13 Jun 2023 22:38:10 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix=20plugin=20mode=20bug=EF=BC=9BOptimize?= =?UTF-8?q?=20the=20parsing=20logic=20for=20model=20response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pilot/out_parser/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pilot/out_parser/base.py b/pilot/out_parser/base.py index 709572d17..a32ef736b 100644 --- a/pilot/out_parser/base.py +++ b/pilot/out_parser/base.py @@ -155,7 +155,7 @@ class BaseOutputParser(ABC): cleaned_output = cleaned_output[: -len("```")] cleaned_output = cleaned_output.strip() if not cleaned_output.startswith("{") or not cleaned_output.endswith("}"): - logger.info("illegal json processing") + logger.info("illegal json processing:\n" + cleaned_output) cleaned_output = self.__extract_json(cleaned_output) cleaned_output = ( cleaned_output.strip() From f36d8223a3013ad50e6d4c5fb009e9b423ec4beb Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 14 Jun 2023 21:28:06 +0800 Subject: [PATCH 2/7] close auto load plugin --- docs/modules/prompts.md | 4 +++- pilot/common/plugins.py | 3 +++ pilot/configs/config.py | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/modules/prompts.md b/docs/modules/prompts.md index 647b93658..2e8f5181d 100644 --- a/docs/modules/prompts.md +++ b/docs/modules/prompts.md @@ -1,3 +1,5 @@ # Prompts -Prompt is a very important part of the interaction between the large model and the user, and to a certain extent, it determines the quality and accuracy of the answer generated by the large model. In this project, we will automatically optimize the corresponding prompt according to user input and usage scenarios, making it easier and more efficient for users to use large language models. \ No newline at end of file +Prompt is a very important part of the interaction between the large model and the user, and to a certain extent, it determines the quality and accuracy of the answer generated by the large model. In this project, we will automatically optimize the corresponding prompt according to user input and usage scenarios, making it easier and more efficient for users to use large language models. + +### 1.DB-GPT Prompt \ No newline at end of file diff --git a/pilot/common/plugins.py b/pilot/common/plugins.py index 09931c90e..2a142d513 100644 --- a/pilot/common/plugins.py +++ b/pilot/common/plugins.py @@ -74,6 +74,9 @@ def create_directory_if_not_exists(directory_path: str) -> bool: 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 diff --git a/pilot/configs/config.py b/pilot/configs/config.py index 06b91e33b..d4ed13f22 100644 --- a/pilot/configs/config.py +++ b/pilot/configs/config.py @@ -90,6 +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_git_branch = os.getenv("PLUGINS_GIT_BRANCH", "plugin_dashboard") @@ -154,8 +155,8 @@ class Config(metaclass=Singleton): ### EMBEDDING Configuration self.EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "text2vec") - self.KNOWLEDGE_CHUNK_SIZE = int(os.getenv("KNOWLEDGE_CHUNK_SIZE", 500)) - self.KNOWLEDGE_SEARCH_TOP_SIZE = int(os.getenv("KNOWLEDGE_SEARCH_TOP_SIZE", 10)) + self.KNOWLEDGE_CHUNK_SIZE = int(os.getenv("KNOWLEDGE_CHUNK_SIZE", 100)) + self.KNOWLEDGE_SEARCH_TOP_SIZE = int(os.getenv("KNOWLEDGE_SEARCH_TOP_SIZE", 5)) ### SUMMARY_CONFIG Configuration self.SUMMARY_CONFIG = os.getenv("SUMMARY_CONFIG", "VECTOR") From db3b0cae508e8970e7a3498fa991d84610edac82 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 14 Jun 2023 21:40:08 +0800 Subject: [PATCH 3/7] 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") From eec43dbfd59c8d8acd1e4564dd2447007984afa9 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 14 Jun 2023 21:46:30 +0800 Subject: [PATCH 4/7] async auto load plugin --- pilot/common/plugins.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pilot/common/plugins.py b/pilot/common/plugins.py index 49c79c4d6..53604fc5c 100644 --- a/pilot/common/plugins.py +++ b/pilot/common/plugins.py @@ -79,8 +79,7 @@ def load_native_plugins(cfg: Config): print("not auto load_native_plugins") return def load_from_git(cfg: Config): - print("load_native_plugins") - ### TODO 默认拉主分支,后续拉发布版本 + print("async load_native_plugins") branch_name = cfg.plugins_git_branch native_plugin_repo = "DB-GPT-Plugins" url = "https://github.com/csunny/{repo}/archive/{branch}.zip" @@ -98,10 +97,10 @@ def load_native_plugins(cfg: Config): print(file_name) with open(file_name, "wb") as f: f.write(response.content) - print("文件已保存到本地") + print("save file") cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode)) else: - print("获取Release信息失败,状态码为:", response.status_code) + print("get file faild,response code:", response.status_code) # 创建一个线程 t = threading.Thread(target=load_from_git, args=(cfg,)) From cc4d70d4d580af1834f61f31073fb1fc8d0dbcb2 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 14 Jun 2023 21:51:05 +0800 Subject: [PATCH 5/7] async auto load plugin --- pilot/common/plugins.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/pilot/common/plugins.py b/pilot/common/plugins.py index 53604fc5c..d8b5c7a07 100644 --- a/pilot/common/plugins.py +++ b/pilot/common/plugins.py @@ -83,24 +83,27 @@ def load_native_plugins(cfg: Config): 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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'}) + try: + 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("save file") - cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode)) - else: - print("get file faild,response code:", 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("save file") + cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode)) + else: + print("get file faild,response code:", response.status_code) + except Exception as e: + print("load plugin from git exception!" + str(e)) # 创建一个线程 t = threading.Thread(target=load_from_git, args=(cfg,)) @@ -108,6 +111,7 @@ def load_native_plugins(cfg: Config): t.start() + def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate]: """Scan the plugins directory for plugins and loads them. From 48eeb3dcb89406dcc40bd547968c3e306cf0c3b3 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 14 Jun 2023 21:54:43 +0800 Subject: [PATCH 6/7] async auto load plugin --- pilot/common/plugins.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pilot/common/plugins.py b/pilot/common/plugins.py index d8b5c7a07..501153bb4 100644 --- a/pilot/common/plugins.py +++ b/pilot/common/plugins.py @@ -84,7 +84,8 @@ def load_native_plugins(cfg: Config): native_plugin_repo = "DB-GPT-Plugins" url = "https://github.com/csunny/{repo}/archive/{branch}.zip" try: - response = requests.get(url.format(repo=native_plugin_repo, branch=branch_name), + session = requests.Session() + response = session.get(url.format(repo=native_plugin_repo, branch=branch_name), headers={'Authorization': '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'}) if response.status_code == 200: From 42a39120c3d16d2cb72ed7e87283e82d65c9b4db Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 14 Jun 2023 21:56:38 +0800 Subject: [PATCH 7/7] async auto load plugin --- pilot/common/plugins.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pilot/common/plugins.py b/pilot/common/plugins.py index 501153bb4..832144d22 100644 --- a/pilot/common/plugins.py +++ b/pilot/common/plugins.py @@ -106,9 +106,7 @@ def load_native_plugins(cfg: Config): except Exception as e: print("load plugin from git exception!" + str(e)) - # 创建一个线程 t = threading.Thread(target=load_from_git, args=(cfg,)) - # 启动线程 t.start()