tools修改

This commit is contained in:
UnCLAS-Prommer
2025-07-25 14:35:59 +08:00
parent 37bf904c45
commit 3a4f343d84
5 changed files with 11 additions and 15 deletions

View File

@@ -60,10 +60,10 @@ class BaseCommand(ABC):
pass
def get_config(self, key: str, default=None):
"""获取插件配置值,支持嵌套键访问
"""获取插件配置值,使用嵌套键访问
Args:
key: 配置键名,支持嵌套访问如 "section.subsection.key"
key: 配置键名,使用嵌套访问如 "section.subsection.key"
default: 默认值
Returns:

View File

@@ -39,11 +39,7 @@ class CompareNumbersTool(BaseTool):
else:
result = f"{num1} 等于 {num2}"
return {"type": "comparison_result", "id": f"{num1}_vs_{num2}", "content": result}
return {"name": self.name, "content": result}
except Exception as e:
logger.error(f"比较数字失败: {str(e)}")
return {"type": "info", "id": f"{num1}_vs_{num2}", "content": f"比较数字失败,炸了: {str(e)}"}
# 注册工具
# register_tool(CompareNumbersTool)
return {"name": self.name, "content": f"比较数字失败,炸了: {str(e)}"}

View File

@@ -1,7 +1,6 @@
from src.tools.tool_can_use.base_tool import BaseTool
from src.person_info.person_info import get_person_info_manager
from src.common.logger import get_logger
import time
logger = get_logger("rename_person_tool")
@@ -24,7 +23,7 @@ class RenamePersonTool(BaseTool):
"required": ["person_name"],
}
async def execute(self, function_args: dict, message_txt=""):
async def execute(self, function_args: dict):
"""
执行取名工具逻辑
@@ -82,7 +81,7 @@ class RenamePersonTool(BaseTool):
content = f"已成功将用户 {person_name_to_find} 的备注名更新为 {new_name}"
logger.info(content)
return {"type": "info", "id": f"rename_success_{time.time()}", "content": content}
return {"name": self.name, "content": content}
else:
logger.warning(f"为用户 {person_id} 调用 qv_person_name 后未能成功获取新昵称。")
# 尝试从内存中获取可能已经更新的名字
@@ -101,4 +100,4 @@ class RenamePersonTool(BaseTool):
except Exception as e:
error_msg = f"重命名失败: {str(e)}"
logger.error(error_msg, exc_info=True)
return {"type": "info_error", "id": f"rename_error_{time.time()}", "content": error_msg}
return {"name": self.name, "content": error_msg}

View File

@@ -172,7 +172,7 @@ class ToolExecutor:
logger.debug(f"{self.log_prefix}执行工具: {tool_name}")
# 执行工具
result = await self.tool_instance._execute_tool_call(tool_call)
result = await self.tool_instance.execute_tool_call(tool_call)
if result:
tool_info = {
@@ -299,7 +299,7 @@ class ToolExecutor:
logger.info(f"{self.log_prefix}直接执行工具: {tool_name}")
result = await self.tool_instance._execute_tool_call(tool_call)
result = await self.tool_instance.execute_tool_call(tool_call)
if result:
tool_info = {

View File

@@ -16,7 +16,8 @@ class ToolUser:
return get_all_tool_definitions()
@staticmethod
async def _execute_tool_call(tool_call):
async def execute_tool_call(tool_call):
# sourcery skip: use-assigned-variable
"""执行特定的工具调用
Args: