From 9855c6b8f5c99499823fa85e372ac1487a00d0c5 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Wed, 20 Mar 2024 15:48:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E7=9A=84=E5=BC=95=E5=85=A5?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/core/app.py | 3 +-- pkg/plugin/context.py | 20 ++++++++++++++++++++ pkg/plugin/host.py | 4 ++++ pkg/plugin/loaders/classic.py | 5 +++-- pkg/plugin/models.py | 16 ++++------------ 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/pkg/core/app.py b/pkg/core/app.py index f21ed5b0..7c9868bf 100644 --- a/pkg/core/app.py +++ b/pkg/core/app.py @@ -85,8 +85,7 @@ class Application: tasks = [] try: - - + tasks = [ asyncio.create_task(self.im_mgr.run()), asyncio.create_task(self.ctrl.run()) diff --git a/pkg/plugin/context.py b/pkg/plugin/context.py index 329914f0..3907489d 100644 --- a/pkg/plugin/context.py +++ b/pkg/plugin/context.py @@ -9,6 +9,26 @@ from ..provider.tools import entities as tools_entities from ..core import app +def register( + name: str, + description: str, + version: str, + author +) -> typing.Callable[[typing.Type[BasePlugin]], typing.Type[BasePlugin]]: + pass + +def handler( + event: typing.Type[events.BaseEventModel] +) -> typing.Callable[[typing.Callable], typing.Callable]: + pass + + +def llm_func( + name: str=None, +) -> typing.Callable: + pass + + class BasePlugin(metaclass=abc.ABCMeta): """插件基类""" diff --git a/pkg/plugin/host.py b/pkg/plugin/host.py index 6149da62..2868875d 100644 --- a/pkg/plugin/host.py +++ b/pkg/plugin/host.py @@ -1,3 +1,7 @@ +# 此模块已过时 +# 请从 pkg.plugin.context 引入 BasePlugin, EventContext 和 APIHost +# 最早将于 v3.4 移除此模块 + from . events import * from . context import EventContext, APIHost as PluginHost diff --git a/pkg/plugin/loaders/classic.py b/pkg/plugin/loaders/classic.py index d5be6ace..b5a733f8 100644 --- a/pkg/plugin/loaders/classic.py +++ b/pkg/plugin/loaders/classic.py @@ -28,8 +28,9 @@ class PluginLoader(loader.PluginLoader): setattr(models, 'on', self.on) setattr(models, 'func', self.func) - setattr(models, 'handler', self.handler) - setattr(models, 'llm_func', self.llm_func) + setattr(context, 'register', self.register) + setattr(context, 'handler', self.handler) + setattr(context, 'llm_func', self.llm_func) def register( self, diff --git a/pkg/plugin/models.py b/pkg/plugin/models.py index 642305e4..b8b499f5 100644 --- a/pkg/plugin/models.py +++ b/pkg/plugin/models.py @@ -1,3 +1,7 @@ +# 此模块已过时,请引入 pkg.plugin.context 中的 register, handler 和 llm_func 来注册插件、事件处理函数和内容函数 +# 各个事件模型请从 pkg.plugin.events 引入 +# 最早将于 v3.4 移除此模块 + from __future__ import annotations import typing @@ -24,15 +28,3 @@ def func( name: str=None, ) -> typing.Callable: pass - - -def handler( - event: typing.Type[BaseEventModel] -) -> typing.Callable[[typing.Callable], typing.Callable]: - pass - - -def llm_func( - name: str=None, -) -> typing.Callable: - pass \ No newline at end of file