fix: Update type hints to use newer Python syntax
- Replace Dict, List, Optional with dict, list, < /dev/null | None syntax - Fix abstract method implementation in message.py - Improve type annotations and function return types - Remove unreachable code in get_current_task_tool.py - Refactor HTML elements to use style attributes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ from src.config.config import global_config
|
||||
from src.common.logger_manager import get_logger
|
||||
from src.plugins.moods.moods import MoodManager
|
||||
|
||||
from typing import Dict, Any
|
||||
from typing import Any
|
||||
|
||||
logger = get_logger("change_mood_tool")
|
||||
|
||||
@@ -22,7 +22,7 @@ class ChangeMoodTool(BaseTool):
|
||||
"required": ["text", "response_set"],
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]:
|
||||
async def execute(self, function_args: dict[str, Any], message_txt: str = "") -> dict[str, Any]:
|
||||
"""执行心情改变
|
||||
|
||||
Args:
|
||||
@@ -30,7 +30,7 @@ class ChangeMoodTool(BaseTool):
|
||||
message_txt: 原始消息文本
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
dict: 工具执行结果
|
||||
"""
|
||||
try:
|
||||
response_set = function_args.get("response_set")
|
||||
|
||||
@@ -19,7 +19,7 @@ class RelationshipTool(BaseTool):
|
||||
"required": ["text", "changed_value", "reason"],
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> dict:
|
||||
async def execute(self, function_args: dict[str, Any], message_txt: str = "") -> dict:
|
||||
"""执行工具功能
|
||||
|
||||
Args:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from src.do_tool.tool_can_use.base_tool import BaseTool
|
||||
from src.plugins.schedule.schedule_generator import bot_schedule
|
||||
from src.common.logger import get_module_logger
|
||||
from typing import Dict, Any
|
||||
from typing import Any
|
||||
from datetime import datetime
|
||||
|
||||
logger = get_module_logger("get_current_task_tool")
|
||||
@@ -21,7 +21,7 @@ class GetCurrentTaskTool(BaseTool):
|
||||
"required": ["start_time", "end_time"],
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]:
|
||||
async def execute(self, function_args: dict[str, Any], message_txt: str = "") -> dict[str, Any]:
|
||||
"""执行获取当前任务或指定时间段的日程信息
|
||||
|
||||
Args:
|
||||
@@ -29,7 +29,7 @@ class GetCurrentTaskTool(BaseTool):
|
||||
message_txt: 原始消息文本,此工具不使用
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
dict: 工具执行结果
|
||||
"""
|
||||
start_time = function_args.get("start_time")
|
||||
end_time = function_args.get("end_time")
|
||||
@@ -55,5 +55,6 @@ class GetCurrentTaskTool(BaseTool):
|
||||
task_info = "\n".join(task_list)
|
||||
else:
|
||||
task_info = f"在 {start_time} 到 {end_time} 之间没有找到日程信息"
|
||||
|
||||
else:
|
||||
task_info = "请提供有效的开始时间和结束时间"
|
||||
return {"name": "get_current_task", "content": f"日程信息: {task_info}"}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from src.do_tool.tool_can_use.base_tool import BaseTool
|
||||
from src.common.logger import get_module_logger
|
||||
from typing import Dict, Any
|
||||
from typing import Any
|
||||
|
||||
logger = get_module_logger("get_mid_memory_tool")
|
||||
|
||||
@@ -18,7 +18,7 @@ class GetMidMemoryTool(BaseTool):
|
||||
"required": ["id"],
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]:
|
||||
async def execute(self, function_args: dict[str, Any], message_txt: str = "") -> dict[str, Any]:
|
||||
"""执行记忆获取
|
||||
|
||||
Args:
|
||||
@@ -26,7 +26,7 @@ class GetMidMemoryTool(BaseTool):
|
||||
message_txt: 原始消息文本
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
dict: 工具执行结果
|
||||
"""
|
||||
try:
|
||||
id = function_args.get("id")
|
||||
|
||||
@@ -17,7 +17,7 @@ class SendEmojiTool(BaseTool):
|
||||
"required": ["text"],
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]:
|
||||
async def execute(self, function_args: dict[str, Any], message_txt: str = "") -> dict[str, Any]:
|
||||
text = function_args.get("text", message_txt)
|
||||
return {
|
||||
"name": "send_emoji",
|
||||
|
||||
@@ -42,7 +42,7 @@ class MyNewTool(BaseTool):
|
||||
message_txt: 原始消息文本
|
||||
|
||||
Returns:
|
||||
Dict: 包含执行结果的字典,必须包含name和content字段
|
||||
dict: 包含执行结果的字典,必须包含name和content字段
|
||||
"""
|
||||
# 实现工具逻辑
|
||||
result = f"工具执行结果: {function_args.get('param1')}"
|
||||
|
||||
@@ -22,11 +22,11 @@ class BaseTool:
|
||||
parameters = None
|
||||
|
||||
@classmethod
|
||||
def get_tool_definition(cls) -> Dict[str, Any]:
|
||||
def get_tool_definition(cls) -> dict[str, Any]:
|
||||
"""获取工具定义,用于LLM工具调用
|
||||
|
||||
Returns:
|
||||
Dict: 工具定义字典
|
||||
dict: 工具定义字典
|
||||
"""
|
||||
if not cls.name or not cls.description or not cls.parameters:
|
||||
raise NotImplementedError(f"工具类 {cls.__name__} 必须定义 name, description 和 parameters 属性")
|
||||
@@ -36,14 +36,14 @@ class BaseTool:
|
||||
"function": {"name": cls.name, "description": cls.description, "parameters": cls.parameters},
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any]) -> Dict[str, Any]:
|
||||
async def execute(self, function_args: dict[str, Any]) -> dict[str, Any]:
|
||||
"""执行工具函数
|
||||
|
||||
Args:
|
||||
function_args: 工具调用参数
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
dict: 工具执行结果
|
||||
"""
|
||||
raise NotImplementedError("子类必须实现execute方法")
|
||||
|
||||
@@ -88,11 +88,11 @@ def discover_tools():
|
||||
logger.info(f"工具发现完成,共注册 {len(TOOL_REGISTRY)} 个工具")
|
||||
|
||||
|
||||
def get_all_tool_definitions() -> List[Dict[str, Any]]:
|
||||
def get_all_tool_definitions() -> List[dict[str, Any]]:
|
||||
"""获取所有已注册工具的定义
|
||||
|
||||
Returns:
|
||||
List[Dict]: 工具定义列表
|
||||
List[dict]: 工具定义列表
|
||||
"""
|
||||
return [tool_class().get_tool_definition() for tool_class in TOOL_REGISTRY.values()]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from src.do_tool.tool_can_use.base_tool import BaseTool
|
||||
from src.common.logger import get_module_logger
|
||||
from typing import Dict, Any
|
||||
from typing import Any
|
||||
|
||||
logger = get_module_logger("compare_numbers_tool")
|
||||
|
||||
@@ -19,15 +19,14 @@ class CompareNumbersTool(BaseTool):
|
||||
"required": ["num1", "num2"],
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any]) -> Dict[str, Any]:
|
||||
async def execute(self, function_args: dict[str, Any]) -> dict[str, Any]:
|
||||
"""执行比较两个数的大小
|
||||
|
||||
Args:
|
||||
function_args: 工具参数
|
||||
message_txt: 原始消息文本
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
dict: 工具执行结果
|
||||
"""
|
||||
try:
|
||||
num1 = function_args.get("num1")
|
||||
|
||||
@@ -2,7 +2,7 @@ from src.do_tool.tool_can_use.base_tool import BaseTool
|
||||
from src.plugins.chat.utils import get_embedding
|
||||
from src.common.database import db
|
||||
from src.common.logger_manager import get_logger
|
||||
from typing import Dict, Any, Union
|
||||
from typing import Any, Union
|
||||
|
||||
logger = get_logger("get_knowledge_tool")
|
||||
|
||||
@@ -21,15 +21,14 @@ class SearchKnowledgeTool(BaseTool):
|
||||
"required": ["query"],
|
||||
}
|
||||
|
||||
async def execute(self, function_args: Dict[str, Any]) -> Dict[str, Any]:
|
||||
async def execute(self, function_args: dict[str, Any]) -> dict[str, Any]:
|
||||
"""执行知识库搜索
|
||||
|
||||
Args:
|
||||
function_args: 工具参数
|
||||
message_txt: 原始消息文本
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
dict: 工具执行结果
|
||||
"""
|
||||
try:
|
||||
query = function_args.get("query")
|
||||
|
||||
@@ -25,7 +25,6 @@ class GetMemoryTool(BaseTool):
|
||||
|
||||
Args:
|
||||
function_args: 工具参数
|
||||
message_txt: 原始消息文本
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
|
||||
@@ -22,7 +22,6 @@ class GetCurrentDateTimeTool(BaseTool):
|
||||
|
||||
Args:
|
||||
function_args: 工具参数(此工具不使用)
|
||||
message_txt: 原始消息文本(此工具不使用)
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
|
||||
@@ -29,7 +29,6 @@ class SearchKnowledgeFromLPMMTool(BaseTool):
|
||||
|
||||
Args:
|
||||
function_args: 工具参数
|
||||
message_txt: 原始消息文本
|
||||
|
||||
Returns:
|
||||
Dict: 工具执行结果
|
||||
|
||||
@@ -106,7 +106,6 @@ class ToolUser:
|
||||
|
||||
Args:
|
||||
message_txt: 用户消息文本
|
||||
sender_name: 发送者名称
|
||||
chat_stream: 聊天流对象
|
||||
observation: 观察对象(可选)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user