🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -6,38 +6,29 @@ from src.do_tool.tool_can_use.base_tool import BaseTool
|
||||
|
||||
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)}"}
|
||||
|
||||
@@ -21,7 +21,9 @@ class ToolUser:
|
||||
model=global_config.llm_heartflow, temperature=0.2, max_tokens=1000, request_type="tool_use"
|
||||
)
|
||||
|
||||
async def _build_tool_prompt(self, message_txt: str, sender_name: str, chat_stream: ChatStream, reply_message:str = ""):
|
||||
async def _build_tool_prompt(
|
||||
self, message_txt: str, sender_name: str, chat_stream: ChatStream, reply_message: str = ""
|
||||
):
|
||||
"""构建工具使用的提示词
|
||||
|
||||
Args:
|
||||
@@ -155,7 +157,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"模型请求调用{len(tool_calls)}个工具: {tool_calls_str}")
|
||||
@@ -166,7 +168,7 @@ class ToolUser:
|
||||
"knowledge": [],
|
||||
"change_relationship": [],
|
||||
"change_mood": [],
|
||||
"other": []
|
||||
"other": [],
|
||||
}
|
||||
|
||||
# 执行所有工具调用
|
||||
@@ -175,18 +177,12 @@ class ToolUser:
|
||||
if result:
|
||||
tool_results.append(result)
|
||||
# 将工具结果添加到对应类型的列表中
|
||||
structured_info[result["type"]].append({
|
||||
"name": result["name"],
|
||||
"content": result["content"]
|
||||
})
|
||||
structured_info[result["type"]].append({"name": result["name"], "content": result["content"]})
|
||||
|
||||
# 如果有工具结果,返回结构化的信息
|
||||
if any(structured_info.values()):
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user