mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
perf: 完善插件加载流程
This commit is contained in:
@@ -67,6 +67,7 @@ class Application:
|
||||
|
||||
async def run(self):
|
||||
await self.plugin_mgr.load_plugins()
|
||||
await self.plugin_mgr.initialize_plugins()
|
||||
|
||||
tasks = [
|
||||
asyncio.create_task(self.im_mgr.run()),
|
||||
|
||||
@@ -92,6 +92,10 @@ async def make_app() -> app.Application:
|
||||
await ver_mgr.initialize()
|
||||
ap.ver_mgr = ver_mgr
|
||||
|
||||
plugin_mgr_inst = plugin_mgr.PluginManager(ap)
|
||||
await plugin_mgr_inst.initialize()
|
||||
ap.plugin_mgr = plugin_mgr_inst
|
||||
|
||||
center_v2_api = center_v2.V2CenterAPI(
|
||||
ap,
|
||||
basic_info={
|
||||
@@ -138,11 +142,6 @@ async def make_app() -> app.Application:
|
||||
ctrl = controller.Controller(ap)
|
||||
ap.ctrl = ctrl
|
||||
|
||||
# TODO make it async
|
||||
plugin_mgr_inst = plugin_mgr.PluginManager(ap)
|
||||
await plugin_mgr_inst.initialize()
|
||||
ap.plugin_mgr = plugin_mgr_inst
|
||||
|
||||
await ap.initialize()
|
||||
|
||||
return ap
|
||||
|
||||
@@ -47,7 +47,13 @@ class PluginManager:
|
||||
self.plugins.sort(key=lambda x: x.priority, reverse=True)
|
||||
|
||||
async def initialize_plugins(self):
|
||||
pass
|
||||
for plugin in self.plugins:
|
||||
try:
|
||||
plugin.plugin_inst = plugin.plugin_class(self.api_host)
|
||||
except Exception as e:
|
||||
self.ap.logger.error(f'插件 {plugin.plugin_name} 初始化失败: {e}')
|
||||
self.ap.logger.exception(e)
|
||||
continue
|
||||
|
||||
async def install_plugin(
|
||||
self,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import typing
|
||||
import traceback
|
||||
|
||||
from ...core import app, entities as core_entities
|
||||
from . import entities
|
||||
@@ -65,7 +66,7 @@ class ToolManager:
|
||||
"""执行函数调用
|
||||
"""
|
||||
|
||||
# return "i'm not sure for the args "+str(parameters)
|
||||
try:
|
||||
|
||||
function = await self.get_function(name)
|
||||
if function is None:
|
||||
@@ -79,3 +80,7 @@ class ToolManager:
|
||||
}
|
||||
|
||||
return await function.func(**parameters)
|
||||
except Exception as e:
|
||||
self.ap.logger.error(f'执行函数 {name} 时发生错误: {e}')
|
||||
traceback.print_exc()
|
||||
return f'error occurred when executing function {name}: {e}'
|
||||
|
||||
Reference in New Issue
Block a user