Plugin_manager#

evofabric.plugin_manager.PluginTypeDict#

插件类型字典,映射基础类到其对应的字符串标识。用于动态加载和注册插件。

Type:

Dict[type, str]

Example:
PluginTypeDict = {

ChatClientBase: "ChatClientBase", EmbedClientBase: "EmbedClientBase", RerankClientBase: "RerankClientBase", SyncNode: "SyncNode", AsyncNode: "AsyncNode", SyncStreamNode: "SyncStreamNode", AsyncStreamNode: "AsyncStreamNode", MemBase: "MemBase", ToolManager: "ToolManager", McpToolManager: "McpToolManager", CodeSandbox: "CodeSandbox", DBBase: "DBBase"

}

evofabric.plugin_manager.load_plugins(parent_cls, tool_type)#

动态加载指定类型的插件,并返回插件类字典。

参数:
  • parent_cls (type) -- 插件基类,加载的插件类会继承此类。

  • tool_type (str) -- 插件类型字符串,对应 entry points 的 group 名称。

返回:

加载的插件字典,键为 entry point 名称,值为动态生成的插件类。

返回类型:

Dict[str, type]

备注

  1. 使用 importlib.metadata.entry_points 获取指定 group 下的所有 entry points。

  2. 调用每个 entry point 的注册函数获取插件的完整类路径。

  3. 动态导入模块并获取插件类对象。

  4. 使用 type 动态创建一个新类,继承自 parent_cls 和插件类。

  5. 将新类添加到返回字典中。

evofabric.plugin_manager.init_plugins()#

初始化所有插件,依据 PluginTypeDict 自动加载对应的插件。

备注

  1. 遍历 PluginTypeDict 中的每个 (插件基类, 工具类型) 对。

  2. 对每个基类和工具类型调用 load_plugins() 进行插件加载。

  3. 该函数主要用于在系统启动时统一初始化所有插件。