mirror of https://github.com/Mai-with-u/MaiBot.git
Update rename_person_tool.py
parent
a2eb4a163b
commit
f39f82e47e
|
|
@ -1,4 +1,4 @@
|
|||
from src.tools.tool_can_use.base_tool import BaseTool, register_tool
|
||||
from src.tools.tool_can_use.base_tool import BaseTool
|
||||
from src.person_info.person_info import person_info_manager
|
||||
from src.common.logger_manager import get_logger
|
||||
import time
|
||||
|
|
@ -9,15 +9,15 @@ logger = get_logger("rename_person_tool")
|
|||
class RenamePersonTool(BaseTool):
|
||||
name = "rename_person"
|
||||
description = (
|
||||
"这个工具可以改变用户的昵称。你可以选择改变对他人的称呼。你想给人改名,叫别人别的称呼,需要调用这个工具。"
|
||||
"This tool can change user nicknames. You can choose to change how you address others. If you want to rename someone or call them by a different name, you need to call this tool."
|
||||
)
|
||||
parameters = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"person_name": {"type": "string", "description": "需要重新取名的用户的当前昵称"},
|
||||
"person_name": {"type": "string", "description": "Current nickname of the user who needs to be renamed"},
|
||||
"message_content": {
|
||||
"type": "string",
|
||||
"description": "当前的聊天内容或特定要求,用于提供取名建议的上下文,尽可能详细。",
|
||||
"description": "Current chat content or specific requirements, used to provide context for naming suggestions, as detailed as possible.",
|
||||
},
|
||||
},
|
||||
"required": ["person_name"],
|
||||
|
|
@ -38,7 +38,7 @@ class RenamePersonTool(BaseTool):
|
|||
request_context = function_args.get("message_content", "") # 如果没有提供,则为空字符串
|
||||
|
||||
if not person_name_to_find:
|
||||
return {"name": self.name, "content": "错误:必须提供需要重命名的用户昵称 (person_name)。"}
|
||||
return {"name": self.name, "content": "Error: Must provide the nickname of the user to be renamed (person_name)."}
|
||||
|
||||
try:
|
||||
# 1. 根据昵称查找用户信息
|
||||
|
|
@ -49,7 +49,7 @@ class RenamePersonTool(BaseTool):
|
|||
logger.info(f"未找到昵称为 '{person_name_to_find}' 的用户。")
|
||||
return {
|
||||
"name": self.name,
|
||||
"content": f"找不到昵称为 '{person_name_to_find}' 的用户。请确保输入的是我之前为该用户取的昵称。",
|
||||
"content": f"Cannot find user with nickname '{person_name_to_find}'. Please ensure you entered the nickname I previously gave to that user.",
|
||||
}
|
||||
|
||||
person_id = person_info.get("person_id")
|
||||
|
|
@ -58,8 +58,8 @@ class RenamePersonTool(BaseTool):
|
|||
user_avatar = person_info.get("user_avatar")
|
||||
|
||||
if not person_id:
|
||||
logger.error(f"找到了用户 '{person_name_to_find}' 但无法获取 person_id")
|
||||
return {"name": self.name, "content": f"找到了用户 '{person_name_to_find}' 但获取内部ID时出错。"}
|
||||
logger.error(f"Found user '{person_name_to_find}' but unable to get person_id")
|
||||
return {"name": self.name, "content": f"Found user '{person_name_to_find}' but error occurred while getting internal ID."}
|
||||
|
||||
# 2. 调用 qv_person_name 进行取名
|
||||
logger.debug(
|
||||
|
|
@ -79,7 +79,7 @@ class RenamePersonTool(BaseTool):
|
|||
# reason = result.get("reason", "未提供理由")
|
||||
logger.info(f"成功为用户 {person_id} 取了新昵称: {new_name}")
|
||||
|
||||
content = f"已成功将用户 {person_name_to_find} 的备注名更新为 {new_name}"
|
||||
content = f"Successfully updated user {person_name_to_find}'s nickname to {new_name}"
|
||||
logger.info(content)
|
||||
return {"type": "info", "id": f"rename_success_{time.time()}", "content": content}
|
||||
else:
|
||||
|
|
@ -89,19 +89,19 @@ class RenamePersonTool(BaseTool):
|
|||
if current_name and current_name != person_name_to_find:
|
||||
return {
|
||||
"name": self.name,
|
||||
"content": f"尝试取新昵称时遇到一点小问题,但我已经将 '{person_name_to_find}' 的昵称更新为 '{current_name}' 了。",
|
||||
"content": f"Encountered a small issue while trying to create a new nickname, but I have already updated '{person_name_to_find}''s nickname to '{current_name}'.",
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"name": self.name,
|
||||
"content": f"尝试为 '{person_name_to_find}' 取新昵称时遇到了问题,未能成功生成。可能需要稍后再试。",
|
||||
"content": f"Encountered a problem while trying to create a new nickname for '{person_name_to_find}', failed to generate successfully. May need to try again later.",
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"重命名失败: {str(e)}"
|
||||
error_msg = f"Rename failed: {str(e)}"
|
||||
logger.error(error_msg, exc_info=True)
|
||||
return {"type": "info_error", "id": f"rename_error_{time.time()}", "content": error_msg}
|
||||
|
||||
|
||||
# 注册工具
|
||||
register_tool(RenamePersonTool)
|
||||
#register_tool(RenamePersonTool)
|
||||
|
|
|
|||
Loading…
Reference in New Issue