From dce6734ba2b73afa503012c780f89b57c3bba388 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Sat, 29 Jul 2023 16:51:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E4=B8=BA=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E4=BD=BF=E7=94=A8func()=E8=A3=85=E9=A5=B0=E5=99=A8=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E5=86=85=E5=AE=B9=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/plugin/models.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/pkg/plugin/models.py b/pkg/plugin/models.py index 17ed2092..d7c8ab22 100644 --- a/pkg/plugin/models.py +++ b/pkg/plugin/models.py @@ -140,12 +140,15 @@ ContentFunction = "content_function" """ -def on(event: str): +def on(*args, **kwargs): """注册事件监听器 - :param - event: str 事件名称 """ - return Plugin.on(event) + return Plugin.on(*args, **kwargs) + +def func(*args, **kwargs): + """注册内容函数 + """ + return Plugin.func(*args, **kwargs) __current_registering_plugin__ = "" @@ -205,6 +208,32 @@ class Plugin: return wrapper + @classmethod + def func(cls, name: str=None): + """内容函数装饰器 + """ + global __current_registering_plugin__ + from CallingGPT.entities.namespace import get_func_schema + + def wrapper(func): + + function_schema = get_func_schema(func) + function_schema['name'] = __current_registering_plugin__ + '-' + (func.__name__ if name is None else name) + + host.__function_inst_map__[function_schema['name']] = function_schema['function'] + + del function_schema['function'] + + # logging.debug("registering content function: p='{}', f='{}', s={}".format(__current_registering_plugin__, func, function_schema)) + + host.__callable_functions__.append( + function_schema + ) + + return func + + return wrapper + def register(name: str, description: str, version: str, author: str): """注册插件, 此函数作为装饰器使用