better:优化回复逻辑,现在回复前会先思考,移除推理模型再回复中的使用,优化心流运行逻辑,优化思考时间计算逻辑,添加错误检测

This commit is contained in:
SengokuCola
2025-03-31 22:34:52 +08:00
parent 42b1b772ef
commit 4c42c90879
14 changed files with 254 additions and 193 deletions

View File

@@ -106,7 +106,7 @@ class Heartflow:
self.current_mind = reponse
logger.info(f"麦麦的总体脑内状态:{self.current_mind}")
# logger.info("麦麦想了想,当前活动:")
await bot_schedule.move_doing(self.current_mind)
# await bot_schedule.move_doing(self.current_mind)
for _, subheartflow in self._subheartflows.items():
subheartflow.main_heartflow_info = reponse

View File

@@ -52,9 +52,9 @@ class ChattingObservation(Observation):
new_messages_str = ""
for msg in new_messages:
if "detailed_plain_text" in msg:
new_messages_str += f"{msg['detailed_plain_text']}\n"
new_messages_str += f"{msg['detailed_plain_text']}"
print(f"new_messages_str{new_messages_str}")
# print(f"new_messages_str{new_messages_str}")
# 将新消息添加到talking_message同时保持列表长度不超过20条
self.talking_message.extend(new_messages)
@@ -112,7 +112,7 @@ class ChattingObservation(Observation):
# 基于已经有的talking_summary和新的talking_message生成一个summary
# print(f"更新聊天总结:{self.talking_summary}")
prompt = ""
prompt = f"你正在参与一个qq群聊的讨论这个群之前在聊的内容是{self.observe_info}\n"
prompt = f"你正在参与一个qq群聊的讨论你记得这个群之前在聊的内容是:{self.observe_info}\n"
prompt += f"现在群里的群友们产生了新的讨论,有了新的发言,具体内容如下:{new_messages_str}\n"
prompt += """以上是群里在进行的聊天,请你对这个聊天内容进行总结,总结内容要包含聊天的大致内容,
以及聊天中的一些重要信息,记得不要分点,不要太长,精简的概括成一段文本\n"""

View File

@@ -87,13 +87,10 @@ class SubHeartflow:
self.is_active = True
self.last_active_time = current_time # 更新最后激活时间
observation = self.observations[0]
await observation.observe()
self.current_state.update_current_state_info()
await self.do_a_thinking()
await self.judge_willing()
# await self.do_a_thinking()
# await self.judge_willing()
await asyncio.sleep(global_config.sub_heart_flow_update_interval)
# 检查是否超过10分钟没有激活
@@ -107,7 +104,7 @@ class SubHeartflow:
observation = self.observations[0]
chat_observe_info = observation.observe_info
print(f"chat_observe_info{chat_observe_info}")
# print(f"chat_observe_info{chat_observe_info}")
# 调取记忆
related_memory = await HippocampusManager.get_instance().get_memory_from_text(
@@ -144,8 +141,57 @@ class SubHeartflow:
self.current_mind = reponse
logger.debug(f"prompt:\n{prompt}\n")
logger.info(f"麦麦的脑内状态:{self.current_mind}")
async def do_observe(self):
observation = self.observations[0]
await observation.observe()
async def do_thinking_before_reply(self, message_txt):
current_thinking_info = self.current_mind
mood_info = self.current_state.mood
mood_info = "你很生气,很愤怒"
observation = self.observations[0]
chat_observe_info = observation.observe_info
# print(f"chat_observe_info{chat_observe_info}")
async def do_after_reply(self, reply_content, chat_talking_prompt):
# 调取记忆
related_memory = await HippocampusManager.get_instance().get_memory_from_text(
text=chat_observe_info, max_memory_num=2, max_memory_length=2, max_depth=3, fast_retrieval=False
)
if related_memory:
related_memory_info = ""
for memory in related_memory:
related_memory_info += memory[1]
else:
related_memory_info = ""
# print(f"相关记忆:{related_memory_info}")
schedule_info = bot_schedule.get_current_num_task(num=1, time_info=False)
prompt = ""
# prompt += f"麦麦的总体想法是:{self.main_heartflow_info}\n\n"
prompt += f"{self.personality_info}\n"
prompt += f"你刚刚在做的事情是:{schedule_info}\n"
if related_memory_info:
prompt += f"你想起来你之前见过的回忆:{related_memory_info}\n以上是你的回忆,不一定是目前聊天里的人说的,也不一定是现在发生的事情,请记住。\n"
prompt += f"刚刚你的想法是{current_thinking_info}\n"
prompt += "-----------------------------------\n"
prompt += f"现在你正在上网和qq群里的网友们聊天群里正在聊的话题是{chat_observe_info}\n"
prompt += f"你现在{mood_info}\n"
prompt += f"你注意到有人刚刚说:{message_txt}\n"
prompt += "现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,"
prompt += "记得结合上述的消息,要记得维持住你的人设,注意自己的名字,关注有人刚刚说的内容,不要思考太多:"
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
self.update_current_mind(reponse)
self.current_mind = reponse
logger.debug(f"prompt:\n{prompt}\n")
logger.info(f"麦麦的思考前脑内状态:{self.current_mind}")
async def do_thinking_after_reply(self, reply_content, chat_talking_prompt):
print("麦麦回复之后脑袋转起来了")
current_thinking_info = self.current_mind
mood_info = self.current_state.mood
@@ -155,10 +201,10 @@ class SubHeartflow:
message_new_info = chat_talking_prompt
reply_info = reply_content
schedule_info = bot_schedule.get_current_num_task(num=1, time_info=False)
# schedule_info = bot_schedule.get_current_num_task(num=1, time_info=False)
prompt = ""
prompt += f"你现在正在做的事情是:{schedule_info}\n"
# prompt += f"你现在正在做的事情是:{schedule_info}\n"
prompt += f"{self.personality_info}\n"
prompt += f"现在你正在上网和qq群里的网友们聊天群里正在聊的话题是{chat_observe_info}\n"
prompt += f"刚刚你的想法是{current_thinking_info}"