diff --git a/pkg/plugin/context.py b/pkg/plugin/context.py index 3907489d..b0e2ef96 100644 --- a/pkg/plugin/context.py +++ b/pkg/plugin/context.py @@ -13,19 +13,64 @@ def register( name: str, description: str, version: str, - author + author: str ) -> typing.Callable[[typing.Type[BasePlugin]], typing.Type[BasePlugin]]: + """注册插件类 + + 使用示例: + + @register( + name="插件名称", + description="插件描述", + version="插件版本", + author="插件作者" + ) + class MyPlugin(BasePlugin): + pass + """ pass def handler( event: typing.Type[events.BaseEventModel] ) -> typing.Callable[[typing.Callable], typing.Callable]: + """注册事件监听器 + + 使用示例: + + class MyPlugin(BasePlugin): + + @handler(NormalMessageResponded) + async def on_normal_message_responded(self, ctx: EventContext): + pass + """ pass def llm_func( name: str=None, ) -> typing.Callable: + """注册内容函数 + + 使用示例: + + class MyPlugin(BasePlugin): + + @llm_func("access_the_web_page") + async def _(self, query, url: str, brief_len: int): + \"""Call this function to search about the question before you answer any questions. + - Do not search through google.com at any time. + - If you need to search somthing, visit https://www.sogou.com/web?query=. + - If user ask you to open a url (start with http:// or https://), visit it directly. + - Summary the plain content result by yourself, DO NOT directly output anything in the result you got. + + Args: + url(str): url to visit + brief_len(int): max length of the plain text content, recommend 1024-4096, prefer 4096 + + Returns: + str: plain text content of the web page or error message(starts with 'error:') + \""" + """ pass diff --git a/pkg/plugin/events.py b/pkg/plugin/events.py index bcb8e5c8..b5919762 100644 --- a/pkg/plugin/events.py +++ b/pkg/plugin/events.py @@ -13,7 +13,7 @@ class BaseEventModel(pydantic.BaseModel): """事件模型基类""" query: typing.Union[core_entities.Query, None] - """此次请求的query对象,可能为None""" + """此次请求的query对象,非请求过程的事件时为None""" class Config: arbitrary_types_allowed = True