🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -32,7 +32,7 @@ class ChatBot:
|
||||
self.think_flow_chat = ThinkFlowChat()
|
||||
self.reasoning_chat = ReasoningChat()
|
||||
self.heartFC_processor = HeartFC_Processor() # 新增
|
||||
|
||||
|
||||
# 创建初始化PFC管理器的任务,会在_ensure_started时执行
|
||||
self.only_process_chat = MessageProcessor()
|
||||
self.pfc_manager = PFCManager.get_instance()
|
||||
|
||||
@@ -276,9 +276,7 @@ class HeartFC_Chat:
|
||||
)
|
||||
self.mood_manager.update_mood_from_emotion(emotion, global_config.mood_intensity_factor)
|
||||
|
||||
|
||||
|
||||
#暂不使用
|
||||
# 暂不使用
|
||||
async def trigger_reply_generation(self, stream_id: str, observed_messages: List[dict]):
|
||||
"""根据 SubHeartflow 的触发信号生成回复 (基于观察)"""
|
||||
stream_name = chat_manager.get_stream_name(stream_id) or stream_id # <--- 在开始时获取名称
|
||||
@@ -534,4 +532,3 @@ class HeartFC_Chat:
|
||||
finally:
|
||||
# 可以在这里添加清理逻辑,如果有的话
|
||||
pass
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ logger = get_module_logger("heartFC_processor", config=processor_config)
|
||||
class HeartFC_Processor:
|
||||
def __init__(self):
|
||||
self.storage = MessageStorage()
|
||||
self.interest_manager = (
|
||||
InterestManager()
|
||||
)
|
||||
self.interest_manager = InterestManager()
|
||||
# self.chat_instance = chat_instance # 持有 HeartFC_Chat 实例
|
||||
|
||||
async def process_message(self, message_data: str) -> None:
|
||||
@@ -44,7 +42,7 @@ class HeartFC_Processor:
|
||||
5. 应用全局配置中的过滤词和正则表达式,过滤不符合规则的消息。
|
||||
6. 查询消息缓冲结果,如果消息被缓冲器拦截(例如,判断为消息轰炸的一部分),则中止后续处理。
|
||||
7. 对于通过缓冲的消息,将其存储到 `MessageStorage` 中。
|
||||
|
||||
|
||||
8. 调用海马体(`HippocampusManager`)计算消息内容的记忆激活率。(这部分算法后续会进行优化)
|
||||
9. 根据是否被提及(@)和记忆激活率,计算最终的兴趣度增量。(提及的额外兴趣增幅)
|
||||
10. 使用计算出的增量更新 `InterestManager` 中对应会话的兴趣度。
|
||||
|
||||
@@ -130,7 +130,7 @@ class InterestChatting:
|
||||
# 限制概率不超过最大值
|
||||
self.current_reply_probability = min(self.current_reply_probability, self.max_reply_probability)
|
||||
|
||||
else:
|
||||
else:
|
||||
if 0 < self.probability_decay_factor < 1:
|
||||
decay_multiplier = math.pow(self.probability_decay_factor, time_delta)
|
||||
# old_prob = self.current_reply_probability
|
||||
|
||||
@@ -45,7 +45,7 @@ PLANNER_TOOL_DEFINITION = [
|
||||
"reasoning": {"type": "string", "description": "做出此决定的简要理由。"},
|
||||
"emoji_query": {
|
||||
"type": "string",
|
||||
"description": '如果行动是\'emoji_reply\',指定表情的主题或概念。如果行动是\'text_reply\'且希望在文本后追加表情,也在此指定表情主题。',
|
||||
"description": "如果行动是'emoji_reply',指定表情的主题或概念。如果行动是'text_reply'且希望在文本后追加表情,也在此指定表情主题。",
|
||||
},
|
||||
},
|
||||
"required": ["action", "reasoning"],
|
||||
@@ -386,9 +386,9 @@ class PFChatting:
|
||||
|
||||
# --- 获取最新的观察信息 ---
|
||||
try:
|
||||
observation = self.sub_hf._get_primary_observation() # Call only once
|
||||
observation = self.sub_hf._get_primary_observation() # Call only once
|
||||
|
||||
if observation: # Now check if the result is truthy
|
||||
if observation: # Now check if the result is truthy
|
||||
# logger.debug(f"{log_prefix}[Planner] 调用 observation.observe()...")
|
||||
await observation.observe() # 主动观察以获取最新消息
|
||||
observed_messages = observation.talking_message # 获取更新后的消息列表
|
||||
@@ -409,7 +409,7 @@ class PFChatting:
|
||||
]
|
||||
observation_context_text = " ".join(context_texts)
|
||||
# logger.debug(f"{log_prefix}[Planner] Context for tools: {observation_context_text[:100]}...")
|
||||
|
||||
|
||||
tool_result = await self.heartfc_chat.tool_user.use_tool(
|
||||
message_txt=observation_context_text, chat_stream=self.chat_stream, sub_heartflow=self.sub_hf
|
||||
)
|
||||
@@ -417,15 +417,12 @@ class PFChatting:
|
||||
tool_result_info = tool_result.get("structured_info", {})
|
||||
logger.debug(f"{log_prefix}[Planner] 规划前工具结果: {tool_result_info}")
|
||||
if "mid_chat_mem" in tool_result_info:
|
||||
get_mid_memory_id = [
|
||||
mem["content"] for mem in tool_result_info["mid_chat_mem"] if "content" in mem
|
||||
]
|
||||
get_mid_memory_id = [mem["content"] for mem in tool_result_info["mid_chat_mem"] if "content" in mem]
|
||||
|
||||
except Exception as e_tool:
|
||||
logger.error(f"{log_prefix}[Planner] 规划前工具使用失败: {e_tool}")
|
||||
# --- 结束工具使用 ---
|
||||
|
||||
|
||||
current_mind, _past_mind = await self.sub_hf.do_thinking_before_reply(
|
||||
chat_stream=self.chat_stream,
|
||||
extra_info=tool_result_info,
|
||||
@@ -713,7 +710,6 @@ class PFChatting:
|
||||
prompt = f"你的名字是 {global_config.BOT_NICKNAME}。是一个女大二学生,正在QQ聊天,正在决定是否以及如何回应当前的聊天。\n"
|
||||
|
||||
# Add current mind state if available
|
||||
|
||||
|
||||
if observed_messages:
|
||||
context_text = " ".join(
|
||||
@@ -724,15 +720,14 @@ class PFChatting:
|
||||
prompt += "\n---\n"
|
||||
else:
|
||||
prompt += "当前没有观察到新的聊天内容。\n"
|
||||
|
||||
|
||||
prompt += "\n看了这些内容,你的想法是:"
|
||||
|
||||
|
||||
if current_mind:
|
||||
prompt += f"\n---\n{current_mind}\n---\n\n"
|
||||
|
||||
|
||||
prompt += (
|
||||
"\n请结合你的内部想法和观察到的聊天内容,分析情况并使用 \'decide_reply_action\' 工具来决定你的最终行动。\n"
|
||||
"\n请结合你的内部想法和观察到的聊天内容,分析情况并使用 'decide_reply_action' 工具来决定你的最终行动。\n"
|
||||
)
|
||||
prompt += "决策依据:\n"
|
||||
prompt += "1. 如果聊天内容无聊、与你无关、或者你的内部想法认为不适合回复,选择 'no_reply'。\n"
|
||||
@@ -742,8 +737,7 @@ class PFChatting:
|
||||
)
|
||||
prompt += "4. 如果你已经回复过消息,也没有人又回复你,选择'no_reply'。\n"
|
||||
prompt += "5. 除非大家都在这么做,否则不要重复聊相同的内容。\n"
|
||||
prompt += "必须调用 \'decide_reply_action\' 工具并提供 \'action\' 和 \'reasoning\'。如果选择了 'emoji_reply' 或者选择了 'text_reply' 并想追加表情,则必须提供 \'emoji_query\'。"
|
||||
|
||||
prompt += "必须调用 'decide_reply_action' 工具并提供 'action' 和 'reasoning'。如果选择了 'emoji_reply' 或者选择了 'text_reply' 并想追加表情,则必须提供 'emoji_query'。"
|
||||
|
||||
prompt = await relationship_manager.convert_all_person_sign_to_person_name(prompt)
|
||||
prompt = parse_text_timestamps(prompt, mode="lite")
|
||||
|
||||
@@ -1257,7 +1257,7 @@ class Hippocampus:
|
||||
logger.info(f"选中记忆: {memory} (来自节点: {topic})")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
async def get_memory_from_topic(
|
||||
self,
|
||||
keywords: list[str],
|
||||
@@ -1343,7 +1343,6 @@ class Hippocampus:
|
||||
else:
|
||||
activate_map[node] = activation_value
|
||||
|
||||
|
||||
# 基于激活值平方的独立概率选择
|
||||
remember_map = {}
|
||||
# logger.info("基于激活值平方的归一化选择:")
|
||||
@@ -1941,7 +1940,7 @@ class HippocampusManager:
|
||||
logger.error(f"文本激活记忆失败: {e}")
|
||||
response = []
|
||||
return response
|
||||
|
||||
|
||||
async def get_memory_from_topic(
|
||||
self,
|
||||
valid_keywords: list[str],
|
||||
|
||||
Reference in New Issue
Block a user