重构函数信息获取逻辑;移除示例测试用例文件

This commit is contained in:
2024-12-15 02:51:37 +08:00
parent 4083aba99f
commit f1064b65db
10 changed files with 399 additions and 166 deletions

View File

@ -1,7 +1,7 @@
from types import ModuleType
from typing import Any
from pydantic import BaseModel
from pydantic import BaseModel, Field
from .typing import ASYNC_FUNCTION_CALL_FUNC, FUNCTION_CALL_FUNC
@ -69,75 +69,3 @@ class Plugin(BaseModel):
def __eq__(self, other: Any) -> bool:
return self.name == other.name
class FunctionCallArgument(BaseModel):
"""
插件函数参数对象
Attributes:
----------
name: str
参数名称
type: str
参数类型 string integer等
description: str
参数描述
"""
type_: str
"""参数类型描述 string integer等"""
description: str
"""参数描述"""
default: Any = None
"""默认值"""
def data(self) -> dict[str, Any]:
return {"type": self.type_, "description": self.description}
class FunctionCall(BaseModel):
"""
插件函数对象
Attributes:
----------
name: str
函数名称
func: "FUNCTION_CALL"
函数对象
"""
name: str
"""函数名称 module.func"""
description: str
"""函数描述 这个函数用于获取天气信息"""
arguments: dict[str, FunctionCallArgument]
"""函数参数信息"""
function: FUNCTION_CALL_FUNC
"""函数对象"""
class Config:
arbitrary_types_allowed = True
def __hash__(self) -> int:
return hash(self.name)
def data(self) -> dict[str, Any]:
"""生成函数描述信息
Returns:
dict[str, Any]: 函数描述信息 字典
"""
return {
"type": "function",
"function": {
"name": self.name,
"description": self.description,
"parameters": {
"type": "object",
"properties": {k: v.data() for k, v in self.arguments.items()},
},
"required": [k for k, v in self.arguments.items() if v.default is None],
},
}