This commit is contained in:
SengokuCola
2025-04-14 21:36:25 +08:00
16 changed files with 56 additions and 73 deletions

View File

@@ -1,4 +1,4 @@
from src.do_tool.tool_can_use.base_tool import BaseTool, register_tool
from src.do_tool.tool_can_use.base_tool import BaseTool
from src.plugins.config.config import global_config
from src.common.logger import get_module_logger
from src.plugins.moods.moods import MoodManager
@@ -11,20 +11,19 @@ logger = get_module_logger("change_mood_tool")
class ChangeMoodTool(BaseTool):
"""改变心情的工具"""
name = "change_mood"
description = "根据收到的内容和自身回复的内容,改变心情,当你回复了别人的消息,你可以使用这个工具"
parameters = {
"type": "object",
"properties": {
"text": {"type": "string", "description": "引起你改变心情的文本"},
"response_set": {"type": "list", "description": "你对文本的回复"}
"response_set": {"type": "list", "description": "你对文本的回复"},
},
"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:
@@ -38,13 +37,13 @@ class ChangeMoodTool(BaseTool):
try:
response_set = function_args.get("response_set")
message_processed_plain_text = function_args.get("text")
mood_manager = MoodManager.get_instance()
gpt = ResponseGenerator()
if response_set is None:
response_set = ["你还没有回复"]
ori_response = ",".join(response_set)
_stance, emotion = await gpt._get_emotion_tags(ori_response, message_processed_plain_text)
mood_manager.update_mood_from_emotion(emotion, global_config.mood_intensity_factor)

View File

@@ -1,43 +1,34 @@
from src.plugins.person_info.relationship_manager import relationship_manager
# from src.plugins.person_info.relationship_manager import relationship_manager
from src.common.logger import get_module_logger
from src.do_tool.tool_can_use.base_tool import BaseTool
from src.plugins.chat_module.think_flow_chat.think_flow_generator import ResponseGenerator
# from src.plugins.chat_module.think_flow_chat.think_flow_generator import ResponseGenerator
logger = get_module_logger("relationship_tool")
class RelationshipTool(BaseTool):
name = "change_relationship"
description = "根据收到的文本和回复内容,修改与特定用户的关系值,当你回复了别人的消息,你可以使用这个工具"
parameters = {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "收到的文本"
},
"changed_value": {
"type": "number",
"description": "变更值"
},
"reason": {
"type": "string",
"description": "变更原因"
}
"text": {"type": "string", "description": "收到的文本"},
"changed_value": {"type": "number", "description": "变更值"},
"reason": {"type": "string", "description": "变更原因"},
},
"required": ["text", "changed_value", "reason"]
"required": ["text", "changed_value", "reason"],
}
async def execute(self, args: dict,message_txt:str) -> dict:
async def execute(self, args: dict, message_txt: str) -> dict:
"""执行工具功能
Args:
args: 包含工具参数的字典
text: 原始消息文本
changed_value: 变更值
reason: 变更原因
Returns:
dict: 包含执行结果的字典
"""
@@ -45,9 +36,9 @@ class RelationshipTool(BaseTool):
text = args.get("text")
changed_value = args.get("changed_value")
reason = args.get("reason")
return {"content": f"因为你刚刚因为{reason},所以你和发[{text}]这条消息的人的关系值变化为{changed_value}"}
except Exception as e:
logger.error(f"修改关系值时发生错误: {str(e)}")
return {"content": f"修改关系值失败: {str(e)}"}
return {"content": f"修改关系值失败: {str(e)}"}

View File

@@ -1,4 +1,4 @@
from src.do_tool.tool_can_use.base_tool import BaseTool, register_tool
from src.do_tool.tool_can_use.base_tool import BaseTool
from src.common.logger import get_module_logger
from typing import Dict, Any

View File

@@ -1,4 +1,4 @@
from src.do_tool.tool_can_use.base_tool import BaseTool, register_tool
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 import get_module_logger

View File

@@ -1,4 +1,4 @@
from src.do_tool.tool_can_use.base_tool import BaseTool, register_tool
from src.do_tool.tool_can_use.base_tool import BaseTool
from src.plugins.memory_system.Hippocampus import HippocampusManager
from src.common.logger import get_module_logger
from typing import Dict, Any

View File

@@ -154,7 +154,7 @@ class ToolUser:
logger.debug("模型返回了空的tool_calls列表")
return {"used_tools": False}
tool_calls_str = ""
tool_calls_str = ""
for tool_call in tool_calls:
tool_calls_str += f"{tool_call['function']['name']}\n"
logger.info(f"根据:\n{prompt}\n模型请求调用{len(tool_calls)}个工具: {tool_calls_str}")
@@ -178,10 +178,7 @@ class ToolUser:
# 如果有工具结果,返回结构化的信息
if structured_info:
logger.info(f"工具调用收集到结构化信息: {json.dumps(structured_info, ensure_ascii=False)}")
return {
"used_tools": True,
"structured_info": structured_info
}
return {"used_tools": True, "structured_info": structured_info}
else:
# 没有工具调用
content, reasoning_content = response