From 52046ba032120b152ea151258696ede3f8b371bf Mon Sep 17 00:00:00 2001 From: Snowykami Date: Sat, 14 Dec 2024 19:56:42 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=9B=B4=E6=96=B0=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=B0=83=E7=94=A8=E6=A8=A1=E5=9E=8B=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=90=8C=E6=AD=A5=E5=87=BD=E6=95=B0=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=9B=E9=87=8D=E6=9E=84=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=9B?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A4=BA=E4=BE=8B=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_marshoai/plugin/models.py | 4 +-- nonebot_plugin_marshoai/plugin/register.py | 32 +++++++++++----------- pyproject.toml | 6 +++- tests/{test_none.py => test_example.py} | 0 tests/test_plugin.py | 20 ++++++++++++++ 5 files changed, 43 insertions(+), 19 deletions(-) rename tests/{test_none.py => test_example.py} (100%) create mode 100644 tests/test_plugin.py diff --git a/nonebot_plugin_marshoai/plugin/models.py b/nonebot_plugin_marshoai/plugin/models.py index ab96e426..260cbb55 100755 --- a/nonebot_plugin_marshoai/plugin/models.py +++ b/nonebot_plugin_marshoai/plugin/models.py @@ -3,7 +3,7 @@ from typing import Any from pydantic import BaseModel -from .typing import ASYNC_FUNCTION_CALL_FUNC +from .typing import ASYNC_FUNCTION_CALL_FUNC, FUNCTION_CALL_FUNC class PluginMetadata(BaseModel): @@ -114,7 +114,7 @@ class FunctionCall(BaseModel): """函数描述 这个函数用于获取天气信息""" arguments: dict[str, FunctionCallArgument] """函数参数信息""" - function: ASYNC_FUNCTION_CALL_FUNC + function: FUNCTION_CALL_FUNC """函数对象""" class Config: diff --git a/nonebot_plugin_marshoai/plugin/register.py b/nonebot_plugin_marshoai/plugin/register.py index 1f281332..90d79c69 100755 --- a/nonebot_plugin_marshoai/plugin/register.py +++ b/nonebot_plugin_marshoai/plugin/register.py @@ -2,17 +2,17 @@ """ import inspect -from typing import Any, Callable, Coroutine, TypeAlias from nonebot import logger +from nonebot_plugin_marshoai.plugin.utils import is_coroutine_callable + from .models import FunctionCall, FunctionCallArgument from .typing import ( ASYNC_FUNCTION_CALL_FUNC, FUNCTION_CALL_FUNC, SYNC_FUNCTION_CALL_FUNC, ) -from .utils import is_coroutine_callable _loaded_functions: dict[str, FUNCTION_CALL_FUNC] = {} @@ -42,21 +42,21 @@ def function_call(*funcs: FUNCTION_CALL_FUNC) -> None: Returns: str: 函数定义信息 """ - for func in funcs: - function_call = get_function_info(func) - # TODO: 注册函数 + # for func in funcs: + # function_call = get_function_info(func) + # # TODO: 注册函数 -def get_function_info(func: FUNCTION_CALL_FUNC): - """获取函数信息 +# def get_function_info(func: FUNCTION_CALL_FUNC) -> FunctionCall: +# """获取函数信息 - Args: - func: 函数对象 +# Args: +# func: 函数对象 - Returns: - FunctionCall: 函数信息对象模型 - """ - name = func.__name__ - description = func.__doc__ - logger.info(f"注册函数: {name} {description}") - # TODO: 获取函数参数信息 +# Returns: +# FunctionCall: 函数信息对象模型 +# """ +# description = func.__doc__ +# # TODO: 获取函数参数信息 +# parameters = {} +# pass diff --git a/pyproject.toml b/pyproject.toml index a110365b..52dde7a2 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,8 @@ dependencies = [ "pyyaml>=6.0.2", "psutil>=6.1.0", "beautifulsoup4>=4.12.3", - "pydantic>=2.10.3" + "pydantic>=2.10.3", + "litedoc>=0.1.0.dev20241214103915" ] license = { text = "MIT, Mulan PSL v2" } @@ -65,3 +66,6 @@ dev = [ "black>=24.10.0", "litedoc>=0.1.0.dev20240906203154", ] +test = [ + "nonebug>=0.4.3", +] diff --git a/tests/test_none.py b/tests/test_example.py similarity index 100% rename from tests/test_none.py rename to tests/test_example.py diff --git a/tests/test_plugin.py b/tests/test_plugin.py new file mode 100644 index 00000000..7f47376d --- /dev/null +++ b/tests/test_plugin.py @@ -0,0 +1,20 @@ +def example_function(num: int, text: str, is_a: bool) -> str: + """这是一个示例描述 + + Args: + num (int): 描述整数 + text (str): 文本类型 + is_a (bool): 布尔类型 + + Returns: + str: 消息 + """ + return "-" + + +class TestPlugin: + def test_get_function_info(self): + from nonebot_plugin_marshoai.plugin import get_function_info + + func_info = get_function_info(example_function) + print(func_info)