加上tools的enum属性

This commit is contained in:
UnCLAS-Prommer
2025-08-03 10:27:47 +08:00
parent 5246a0bb34
commit 1f53ecff10
8 changed files with 55 additions and 29 deletions

View File

@@ -18,11 +18,13 @@ from .base import (
ActionInfo,
CommandInfo,
PluginInfo,
ToolInfo,
PythonDependency,
BaseEventHandler,
EventHandlerInfo,
EventType,
MaiMessages,
ToolParamType,
)
# 导入工具模块
@@ -83,9 +85,11 @@ __all__ = [
"ActionInfo",
"CommandInfo",
"PluginInfo",
"ToolInfo",
"PythonDependency",
"EventHandlerInfo",
"EventType",
"ToolParamType",
# 消息
"MaiMessages",
# 装饰器

View File

@@ -22,6 +22,7 @@ from .component_types import (
EventHandlerInfo,
EventType,
MaiMessages,
ToolParamType,
)
from .config_types import ConfigField
@@ -44,4 +45,5 @@ __all__ = [
"EventType",
"BaseEventHandler",
"MaiMessages",
"ToolParamType",
]

View File

@@ -3,7 +3,7 @@ from typing import Any, List, Tuple
from rich.traceback import install
from src.common.logger import get_logger
from src.plugin_system.base.component_types import ComponentType, ToolInfo
from src.plugin_system.base.component_types import ComponentType, ToolInfo, ToolParamType
install(extra_lines=3)
@@ -17,8 +17,15 @@ class BaseTool(ABC):
"""工具的名称"""
description: str = ""
"""工具的描述"""
parameters: List[Tuple[str, str, str, bool]] = []
"""工具的参数定义,为[("param_name", "param_type", "description", required)]"""
parameters: List[Tuple[str, ToolParamType, str, bool, List[str] | None]] = []
"""工具的参数定义,为[("param_name", param_type, "description", required, enum_values)]格式
param_name: 参数名称
param_type: 参数类型
description: 参数描述
required: 是否必填
enum_values: 枚举值列表
例如: [("arg1", ToolParamType.STRING, "参数1描述", True, None), ("arg2", ToolParamType.INTEGER, "参数2描述", False, ["1", "2", "3"])]
"""
available_for_llm: bool = False
"""是否可供LLM使用"""

View File

@@ -3,6 +3,7 @@ from typing import Dict, Any, List, Optional, Tuple
from dataclasses import dataclass, field
from maim_message import Seg
from src.llm_models.payload_content.tool_option import ToolParamType as ToolParamType
# 组件类型枚举
class ComponentType(Enum):
@@ -145,17 +146,19 @@ class CommandInfo(ComponentInfo):
def __post_init__(self):
super().__post_init__()
self.component_type = ComponentType.COMMAND
@dataclass
class ToolInfo(ComponentInfo):
"""工具组件信息"""
tool_parameters: List[Tuple[str, str, str, bool]] = field(default_factory=list) # 工具参数定义
tool_parameters: List[Tuple[str, ToolParamType, str, bool, List[str] | None]] = field(default_factory=list) # 工具参数定义
tool_description: str = "" # 工具描述
def __post_init__(self):
super().__post_init__()
self.component_type = ComponentType.TOOL
self.component_type = ComponentType.TOOL
@dataclass
class EventHandlerInfo(ComponentInfo):