🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-04-14 04:01:29 +00:00
parent 38d7d9e014
commit 9c82f1322e
7 changed files with 69 additions and 84 deletions

View File

@@ -136,8 +136,6 @@ class ThinkFlowChat:
message_manager.add_message(bot_message)
async def _update_relationship(self, message: MessageRecv, response_set):
"""更新关系情绪"""
ori_response = ",".join(response_set)
@@ -260,16 +258,17 @@ class ThinkFlowChat:
logger.error(f"心流观察失败: {e}")
info_catcher.catch_after_observe(timing_results["观察"])
# 思考前使用工具
update_relationship = ""
try:
with Timer("思考前使用工具", timing_results):
tool_result = await self.tool_user.use_tool(message.processed_plain_text, message.message_info.user_info.user_nickname, chat)
tool_result = await self.tool_user.use_tool(
message.processed_plain_text, message.message_info.user_info.user_nickname, chat
)
# 如果工具被使用且获得了结果,将收集到的信息合并到思考中
collected_info = ""
if tool_result.get("used_tools", False):
# 如果有收集到的结构化信息,将其格式化后添加到当前思考中
if "structured_info" in tool_result:
info = tool_result["structured_info"]
@@ -278,19 +277,19 @@ class ThinkFlowChat:
collected_info += "\n记忆相关信息:\n"
for mem in info["memory"]:
collected_info += f"- {mem['name']}: {mem['content']}\n"
# 处理日程信息
if info["schedule"]:
collected_info += "\n日程相关信息:\n"
for sch in info["schedule"]:
collected_info += f"- {sch['name']}: {sch['content']}\n"
# 处理知识信息
if info["knowledge"]:
collected_info += "\n知识相关信息:\n"
for know in info["knowledge"]:
collected_info += f"- {know['name']}: {know['content']}\n"
# 处理关系信息
if info["change_relationship"]:
collected_info += "\n关系相关信息:\n"
@@ -305,7 +304,7 @@ class ThinkFlowChat:
collected_info += "\n心情相关信息:\n"
for mood in info["change_mood"]:
collected_info += f"- {mood['name']}: {mood['content']}\n"
# 处理其他信息
if info["other"]:
collected_info += "\n其他相关信息:\n"
@@ -314,18 +313,18 @@ class ThinkFlowChat:
except Exception as e:
logger.error(f"思考前工具调用失败: {e}")
logger.error(traceback.format_exc())
if update_relationship:
# ori_response = ",".join(response_set)
# print("22222222222222222222222222222")
stance, emotion = await self.gpt._get_emotion_tags_with_reason("你还没有回复", message.processed_plain_text,update_relationship)
stance, emotion = await self.gpt._get_emotion_tags_with_reason(
"你还没有回复", message.processed_plain_text, update_relationship
)
await relationship_manager.calculate_update_relationship_value(
chat_stream=message.chat_stream, label=emotion, stance=stance
)
)
print("33333333333333333333333333333")
# 思考前脑内状态
try:
with Timer("思考前脑内状态", timing_results):
@@ -335,7 +334,7 @@ class ThinkFlowChat:
message_txt=message.processed_plain_text,
sender_name=message.message_info.user_info.user_nickname,
chat_stream=chat,
extra_info=collected_info
extra_info=collected_info,
)
except Exception as e:
logger.error(f"心流思考前脑内状态失败: {e}")
@@ -370,15 +369,15 @@ class ThinkFlowChat:
except Exception as e:
logger.error(f"心流处理表情包失败: {e}")
# 思考后使用工具
try:
with Timer("思考后使用工具", timing_results):
tool_result = await self.tool_user.use_tool(message.processed_plain_text, message.message_info.user_info.user_nickname, chat)
tool_result = await self.tool_user.use_tool(
message.processed_plain_text, message.message_info.user_info.user_nickname, chat
)
# 如果工具被使用且获得了结果,将收集到的信息合并到思考中
collected_info = ""
if tool_result.get("used_tools", False):
# 如果有收集到的结构化信息,将其格式化后添加到当前思考中
if "structured_info" in tool_result:
info = tool_result["structured_info"]
@@ -387,31 +386,31 @@ class ThinkFlowChat:
collected_info += "\n记忆相关信息:\n"
for mem in info["memory"]:
collected_info += f"- {mem['name']}: {mem['content']}\n"
# 处理日程信息
if info["schedule"]:
collected_info += "\n日程相关信息:\n"
for sch in info["schedule"]:
collected_info += f"- {sch['name']}: {sch['content']}\n"
# 处理知识信息
if info["knowledge"]:
collected_info += "\n知识相关信息:\n"
for know in info["knowledge"]:
collected_info += f"- {know['name']}: {know['content']}\n"
# 处理关系信息
if info["change_relationship"]:
collected_info += "\n关系相关信息:\n"
for rel in info["change_relationship"]:
collected_info += f"- {rel['name']}: {rel['content']}\n"
# 处理心情信息
if info["change_mood"]:
collected_info += "\n心情相关信息:\n"
for mood in info["change_mood"]:
collected_info += f"- {mood['name']}: {mood['content']}\n"
# 处理其他信息
if info["other"]:
collected_info += "\n其他相关信息:\n"
@@ -424,13 +423,13 @@ class ThinkFlowChat:
# 更新关系
if info["change_relationship"]:
ori_response = ",".join(response_set)
stance, emotion = await self.gpt._get_emotion_tags(ori_response, message.processed_plain_text,info["change_relationship"]["content"])
stance, emotion = await self.gpt._get_emotion_tags(
ori_response, message.processed_plain_text, info["change_relationship"]["content"]
)
await relationship_manager.calculate_update_relationship_value(
chat_stream=message.chat_stream, label=emotion, stance=stance
)
try:
with Timer("思考后脑内状态更新", timing_results):
stream_id = message.chat_stream.stream_id
@@ -440,11 +439,12 @@ class ThinkFlowChat:
stream_id, limit=global_config.MAX_CONTEXT_SIZE, combine=True
)
await heartflow.get_subheartflow(stream_id).do_thinking_after_reply(response_set, chat_talking_prompt,collected_info)
await heartflow.get_subheartflow(stream_id).do_thinking_after_reply(
response_set, chat_talking_prompt, collected_info
)
except Exception as e:
logger.error(f"心流思考后脑内状态更新失败: {e}")
# 回复后处理
await willing_manager.after_generate_reply_handle(message.message_info.message_id)

View File

@@ -225,8 +225,7 @@ class ResponseGenerator:
except Exception as e:
logger.debug(f"获取情感标签时出错: {e}")
return "中立", "平静" # 出错时返回默认值
async def _get_emotion_tags_with_reason(self, content: str, processed_plain_text: str, reason: str):
"""提取情感标签,结合立场和情绪"""
try:

View File

@@ -84,10 +84,10 @@ class RelationshipManager:
2.关系越差,改善越难,关系越好,恶化越容易
3.人维护关系的精力往往有限,所以当高关系值用户越多,对于中高关系值用户增长越慢
4.连续正面或负面情感会正反馈
返回:
用户昵称,变更值,变更后关系等级
"""
stancedict = {
"支持": 0,
@@ -159,10 +159,12 @@ class RelationshipManager:
)
await person_info_manager.update_one_field(person_id, "relationship_value", old_value + value, data)
return chat_stream.user_info.user_nickname,value,relationship_level[level_num]
async def calculate_update_relationship_value_with_reason(self, chat_stream: ChatStream, label: str, stance: str, reason: str) -> tuple:
return chat_stream.user_info.user_nickname, value, relationship_level[level_num]
async def calculate_update_relationship_value_with_reason(
self, chat_stream: ChatStream, label: str, stance: str, reason: str
) -> tuple:
"""计算并变更关系值
新的关系值变更计算方式:
将关系值限定在-1000到1000
@@ -171,10 +173,10 @@ class RelationshipManager:
2.关系越差,改善越难,关系越好,恶化越容易
3.人维护关系的精力往往有限,所以当高关系值用户越多,对于中高关系值用户增长越慢
4.连续正面或负面情感会正反馈
返回:
用户昵称,变更值,变更后关系等级
"""
stancedict = {
"支持": 0,
@@ -246,8 +248,8 @@ class RelationshipManager:
)
await person_info_manager.update_one_field(person_id, "relationship_value", old_value + value, data)
return chat_stream.user_info.user_nickname,value,relationship_level[level_num]
return chat_stream.user_info.user_nickname, value, relationship_level[level_num]
async def build_relationship_info(self, person) -> str:
person_id = person_info_manager.get_person_id(person[0], person[1])