Snowykami 52046ba032
Some checks failed
Deploy VitePress site to Pages / build (push) Failing after 38s
Pre-commit checks / pre-commit (3.11) (push) Successful in 2m40s
Pre-commit checks / pre-commit (3.10) (push) Successful in 3m19s
Pre-commit checks / pre-commit (3.12) (push) Successful in 3m19s
Pre-commit checks / pre-commit (3.13) (push) Successful in 3m23s
Pytest API Testing / Pytest (3.11) (push) Failing after 2m10s
Pytest API Testing / Pytest (3.10) (push) Failing after 2m51s
Pytest API Testing / Pytest (3.12) (push) Failing after 2m46s
Pytest API Testing / Pytest (3.13) (push) Failing after 2m39s
更新函数调用模型,添加同步函数类型支持;重构函数信息获取逻辑;新增示例测试用例
2024-12-14 19:56:42 +08:00

63 lines
1.5 KiB
Python
Executable File

"""此模块用于获取function call中函数定义信息以及注册函数
"""
import inspect
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,
)
_loaded_functions: dict[str, FUNCTION_CALL_FUNC] = {}
def async_wrapper(func: SYNC_FUNCTION_CALL_FUNC) -> ASYNC_FUNCTION_CALL_FUNC:
"""将同步函数包装为异步函数,但是不会真正异步执行,仅用于统一调用及函数签名
Args:
func: 同步函数
Returns:
ASYNC_FUNCTION_CALL: 异步函数
"""
async def wrapper(*args, **kwargs) -> str:
return func(*args, **kwargs)
return wrapper
def function_call(*funcs: FUNCTION_CALL_FUNC) -> None:
"""返回一个装饰器,装饰一个函数, 使其注册为一个可被AI调用的function call函数
Args:
func: 函数对象,要有完整的 Google Style Docstring
Returns:
str: 函数定义信息
"""
# for func in funcs:
# function_call = get_function_info(func)
# # TODO: 注册函数
# def get_function_info(func: FUNCTION_CALL_FUNC) -> FunctionCall:
# """获取函数信息
# Args:
# func: 函数对象
# Returns:
# FunctionCall: 函数信息对象模型
# """
# description = func.__doc__
# # TODO: 获取函数参数信息
# parameters = {}
# pass