mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-17 15:58:25 +00:00
async auto load plugin
This commit is contained in:
parent
eec43dbfd5
commit
cc4d70d4d5
@ -83,24 +83,27 @@ def load_native_plugins(cfg: Config):
|
|||||||
branch_name = cfg.plugins_git_branch
|
branch_name = cfg.plugins_git_branch
|
||||||
native_plugin_repo = "DB-GPT-Plugins"
|
native_plugin_repo = "DB-GPT-Plugins"
|
||||||
url = "https://github.com/csunny/{repo}/archive/{branch}.zip"
|
url = "https://github.com/csunny/{repo}/archive/{branch}.zip"
|
||||||
response = requests.get(url.format(repo=native_plugin_repo, branch=branch_name),
|
try:
|
||||||
headers={'Authorization': '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'})
|
response = requests.get(url.format(repo=native_plugin_repo, branch=branch_name),
|
||||||
|
headers={'Authorization': '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'})
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
plugins_path_path = Path(PLUGINS_DIR)
|
plugins_path_path = Path(PLUGINS_DIR)
|
||||||
files = glob.glob(os.path.join(plugins_path_path, f'{native_plugin_repo}*'))
|
files = glob.glob(os.path.join(plugins_path_path, f'{native_plugin_repo}*'))
|
||||||
for file in files:
|
for file in files:
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
time_str = now.strftime('%Y%m%d%H%M%S')
|
time_str = now.strftime('%Y%m%d%H%M%S')
|
||||||
file_name = f"{plugins_path_path}/{native_plugin_repo}-{branch_name}-{time_str}.zip"
|
file_name = f"{plugins_path_path}/{native_plugin_repo}-{branch_name}-{time_str}.zip"
|
||||||
print(file_name)
|
print(file_name)
|
||||||
with open(file_name, "wb") as f:
|
with open(file_name, "wb") as f:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
print("save file")
|
print("save file")
|
||||||
cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode))
|
cfg.set_plugins(scan_plugins(cfg, cfg.debug_mode))
|
||||||
else:
|
else:
|
||||||
print("get file faild,response code:", response.status_code)
|
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,))
|
t = threading.Thread(target=load_from_git, args=(cfg,))
|
||||||
@ -108,6 +111,7 @@ def load_native_plugins(cfg: Config):
|
|||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate]:
|
def scan_plugins(cfg: Config, debug: bool = False) -> List[AutoGPTPluginTemplate]:
|
||||||
"""Scan the plugins directory for plugins and loads them.
|
"""Scan the plugins directory for plugins and loads them.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user