mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-20 03:16:14 +00:00
perf: 完善插件加载流程
This commit is contained in:
@@ -67,6 +67,7 @@ class Application:
|
|||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
await self.plugin_mgr.load_plugins()
|
await self.plugin_mgr.load_plugins()
|
||||||
|
await self.plugin_mgr.initialize_plugins()
|
||||||
|
|
||||||
tasks = [
|
tasks = [
|
||||||
asyncio.create_task(self.im_mgr.run()),
|
asyncio.create_task(self.im_mgr.run()),
|
||||||
|
|||||||
+4
-5
@@ -92,6 +92,10 @@ async def make_app() -> app.Application:
|
|||||||
await ver_mgr.initialize()
|
await ver_mgr.initialize()
|
||||||
ap.ver_mgr = ver_mgr
|
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(
|
center_v2_api = center_v2.V2CenterAPI(
|
||||||
ap,
|
ap,
|
||||||
basic_info={
|
basic_info={
|
||||||
@@ -137,11 +141,6 @@ async def make_app() -> app.Application:
|
|||||||
|
|
||||||
ctrl = controller.Controller(ap)
|
ctrl = controller.Controller(ap)
|
||||||
ap.ctrl = ctrl
|
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()
|
await ap.initialize()
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,13 @@ class PluginManager:
|
|||||||
self.plugins.sort(key=lambda x: x.priority, reverse=True)
|
self.plugins.sort(key=lambda x: x.priority, reverse=True)
|
||||||
|
|
||||||
async def initialize_plugins(self):
|
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(
|
async def install_plugin(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
|
import traceback
|
||||||
|
|
||||||
from ...core import app, entities as core_entities
|
from ...core import app, entities as core_entities
|
||||||
from . import entities
|
from . import entities
|
||||||
@@ -65,17 +66,21 @@ class ToolManager:
|
|||||||
"""执行函数调用
|
"""执行函数调用
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# return "i'm not sure for the args "+str(parameters)
|
try:
|
||||||
|
|
||||||
function = await self.get_function(name)
|
function = await self.get_function(name)
|
||||||
if function is None:
|
if function is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
parameters = parameters.copy()
|
parameters = parameters.copy()
|
||||||
|
|
||||||
parameters = {
|
parameters = {
|
||||||
"query": query,
|
"query": query,
|
||||||
**parameters
|
**parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
return await function.func(**parameters)
|
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