better:优化统计和心流提示词
This commit is contained in:
@@ -81,7 +81,7 @@ MEMORY_STYLE_CONFIG = {
|
|||||||
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}"),
|
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}"),
|
||||||
},
|
},
|
||||||
"simple": {
|
"simple": {
|
||||||
"console_format": ("<green>{time:MM-DD HH:mm}</green> | <light-yellow>海马体</light-yellow> | {message}"),
|
"console_format": ("<green>{time:MM-DD HH:mm}</green> | <light-yellow>海马体</light-yellow> | <light-yellow>{message}</light-yellow>"),
|
||||||
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}"),
|
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ SUB_HEARTFLOW_STYLE_CONFIG = {
|
|||||||
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}"),
|
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}"),
|
||||||
},
|
},
|
||||||
"simple": {
|
"simple": {
|
||||||
"console_format": ("<green>{time:MM-DD HH:mm}</green> | <light-blue>麦麦小脑袋</light-blue> | <green>{message}</green>"), # noqa: E501
|
"console_format": ("<green>{time:MM-DD HH:mm}</green> | <light-blue>麦麦小脑袋</light-blue> | <light-blue>{message}</light-blue>"), # noqa: E501
|
||||||
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}"),
|
"file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class PromptBuilder:
|
|||||||
text=message_txt,
|
text=message_txt,
|
||||||
max_memory_num=3,
|
max_memory_num=3,
|
||||||
max_memory_length=2,
|
max_memory_length=2,
|
||||||
max_depth=3,
|
max_depth=4,
|
||||||
fast_retrieval=False
|
fast_retrieval=False
|
||||||
)
|
)
|
||||||
memory_str = ""
|
memory_str = ""
|
||||||
|
|||||||
@@ -1046,14 +1046,14 @@ class Hippocampus:
|
|||||||
# 将选中的节点添加到remember_map
|
# 将选中的节点添加到remember_map
|
||||||
for node, normalized_activation in sorted_nodes:
|
for node, normalized_activation in sorted_nodes:
|
||||||
remember_map[node] = activate_map[node] # 使用原始激活值
|
remember_map[node] = activate_map[node] # 使用原始激活值
|
||||||
logger.info(
|
logger.debug(
|
||||||
f"节点 '{node}' (归一化激活值: {normalized_activation:.2f}, 激活值: {activate_map[node]:.2f})")
|
f"节点 '{node}' (归一化激活值: {normalized_activation:.2f}, 激活值: {activate_map[node]:.2f})")
|
||||||
else:
|
else:
|
||||||
logger.info("没有有效的激活值")
|
logger.info("没有有效的激活值")
|
||||||
|
|
||||||
# 从选中的节点中提取记忆
|
# 从选中的节点中提取记忆
|
||||||
all_memories = []
|
all_memories = []
|
||||||
logger.info("开始从选中的节点中提取记忆:")
|
# logger.info("开始从选中的节点中提取记忆:")
|
||||||
for node, activation in remember_map.items():
|
for node, activation in remember_map.items():
|
||||||
logger.debug(f"处理节点 '{node}' (激活值: {activation:.2f}):")
|
logger.debug(f"处理节点 '{node}' (激活值: {activation:.2f}):")
|
||||||
node_data = self.memory_graph.G.nodes[node]
|
node_data = self.memory_graph.G.nodes[node]
|
||||||
|
|||||||
@@ -44,13 +44,19 @@ class LLMStatistics:
|
|||||||
|
|
||||||
def _record_online_time(self):
|
def _record_online_time(self):
|
||||||
"""记录在线时间"""
|
"""记录在线时间"""
|
||||||
try:
|
current_time = datetime.now()
|
||||||
|
# 检查5分钟内是否已有记录
|
||||||
|
recent_record = db.online_time.find_one({
|
||||||
|
"timestamp": {
|
||||||
|
"$gte": current_time - timedelta(minutes=5)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if not recent_record:
|
||||||
db.online_time.insert_one({
|
db.online_time.insert_one({
|
||||||
"timestamp": datetime.now(),
|
"timestamp": current_time,
|
||||||
"duration": 5 # 5分钟
|
"duration": 5 # 5分钟
|
||||||
})
|
})
|
||||||
except Exception:
|
|
||||||
logger.exception("记录在线时间失败")
|
|
||||||
|
|
||||||
def _collect_statistics_for_period(self, start_time: datetime) -> Dict[str, Any]:
|
def _collect_statistics_for_period(self, start_time: datetime) -> Dict[str, Any]:
|
||||||
"""收集指定时间段的LLM请求统计数据
|
"""收集指定时间段的LLM请求统计数据
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class Heartflow:
|
|||||||
self._subheartflows = {}
|
self._subheartflows = {}
|
||||||
self.active_subheartflows_nums = 0
|
self.active_subheartflows_nums = 0
|
||||||
|
|
||||||
|
self.personality_info = " ".join(global_config.PROMPT_PERSONALITY)
|
||||||
|
|
||||||
|
|
||||||
async def heartflow_start_working(self):
|
async def heartflow_start_working(self):
|
||||||
@@ -46,13 +47,13 @@ class Heartflow:
|
|||||||
logger.info("麦麦大脑袋转起来了")
|
logger.info("麦麦大脑袋转起来了")
|
||||||
self.current_state.update_current_state_info()
|
self.current_state.update_current_state_info()
|
||||||
|
|
||||||
personality_info = " ".join(global_config.PROMPT_PERSONALITY)
|
personality_info = self.personality_info
|
||||||
current_thinking_info = self.current_mind
|
current_thinking_info = self.current_mind
|
||||||
mood_info = self.current_state.mood
|
mood_info = self.current_state.mood
|
||||||
related_memory_info = 'memory'
|
related_memory_info = 'memory'
|
||||||
sub_flows_info = await self.get_all_subheartflows_minds()
|
sub_flows_info = await self.get_all_subheartflows_minds()
|
||||||
|
|
||||||
schedule_info = bot_schedule.get_current_num_task(num = 5,time_info = True)
|
schedule_info = bot_schedule.get_current_num_task(num = 4,time_info = True)
|
||||||
|
|
||||||
prompt = ""
|
prompt = ""
|
||||||
prompt += f"你刚刚在做的事情是:{schedule_info}\n"
|
prompt += f"你刚刚在做的事情是:{schedule_info}\n"
|
||||||
@@ -91,7 +92,7 @@ class Heartflow:
|
|||||||
return await self.minds_summary(sub_minds)
|
return await self.minds_summary(sub_minds)
|
||||||
|
|
||||||
async def minds_summary(self,minds_str):
|
async def minds_summary(self,minds_str):
|
||||||
personality_info = " ".join(BotConfig.PROMPT_PERSONALITY)
|
personality_info = self.personality_info
|
||||||
mood_info = self.current_state.mood
|
mood_info = self.current_state.mood
|
||||||
|
|
||||||
prompt = ""
|
prompt = ""
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class SubHeartflow:
|
|||||||
|
|
||||||
related_memory = await HippocampusManager.get_instance().get_memory_from_text(
|
related_memory = await HippocampusManager.get_instance().get_memory_from_text(
|
||||||
text=message_stream_info,
|
text=message_stream_info,
|
||||||
max_memory_num=3,
|
max_memory_num=2,
|
||||||
max_memory_length=2,
|
max_memory_length=2,
|
||||||
max_depth=3,
|
max_depth=3,
|
||||||
fast_retrieval=False
|
fast_retrieval=False
|
||||||
@@ -96,10 +96,12 @@ class SubHeartflow:
|
|||||||
prompt += f"你刚刚在做的事情是:{schedule_info}\n"
|
prompt += f"你刚刚在做的事情是:{schedule_info}\n"
|
||||||
# prompt += f"麦麦的总体想法是:{self.main_heartflow_info}\n\n"
|
# prompt += f"麦麦的总体想法是:{self.main_heartflow_info}\n\n"
|
||||||
prompt += f"你{self.personality_info}\n"
|
prompt += f"你{self.personality_info}\n"
|
||||||
prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{message_stream_info}\n"
|
|
||||||
if related_memory_info:
|
if related_memory_info:
|
||||||
prompt += f"你想起来{related_memory_info}。"
|
prompt += f"你想起来你之前见过的回忆:{related_memory_info}。\n以上是你的回忆,不一定是目前聊天里的人说的,也不一定是现在发生的事情,请记住。\n"
|
||||||
prompt += f"刚刚你的想法是{current_thinking_info}。"
|
prompt += f"刚刚你的想法是{current_thinking_info}。\n"
|
||||||
|
prompt += "-----------------------------------\n"
|
||||||
|
if message_stream_info:
|
||||||
|
prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{message_stream_info}\n"
|
||||||
prompt += f"你现在{mood_info}。\n"
|
prompt += f"你现在{mood_info}。\n"
|
||||||
prompt += "现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,"
|
prompt += "现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,"
|
||||||
prompt += "但是记得结合上述的消息,要记得维持住你的人设,关注聊天和新内容,不要思考太多:"
|
prompt += "但是记得结合上述的消息,要记得维持住你的人设,关注聊天和新内容,不要思考太多:"
|
||||||
@@ -108,7 +110,7 @@ class SubHeartflow:
|
|||||||
self.update_current_mind(reponse)
|
self.update_current_mind(reponse)
|
||||||
|
|
||||||
self.current_mind = reponse
|
self.current_mind = reponse
|
||||||
print(prompt)
|
logger.info(f"prompt:\n{prompt}\n")
|
||||||
logger.info(f"麦麦的脑内状态:{self.current_mind}")
|
logger.info(f"麦麦的脑内状态:{self.current_mind}")
|
||||||
|
|
||||||
async def do_after_reply(self,reply_content,chat_talking_prompt):
|
async def do_after_reply(self,reply_content,chat_talking_prompt):
|
||||||
@@ -117,7 +119,7 @@ class SubHeartflow:
|
|||||||
|
|
||||||
current_thinking_info = self.current_mind
|
current_thinking_info = self.current_mind
|
||||||
mood_info = self.current_state.mood
|
mood_info = self.current_state.mood
|
||||||
related_memory_info = 'memory'
|
# related_memory_info = 'memory'
|
||||||
message_stream_info = self.outer_world.talking_summary
|
message_stream_info = self.outer_world.talking_summary
|
||||||
message_new_info = chat_talking_prompt
|
message_new_info = chat_talking_prompt
|
||||||
reply_info = reply_content
|
reply_info = reply_content
|
||||||
@@ -129,8 +131,8 @@ class SubHeartflow:
|
|||||||
prompt += f"你{self.personality_info}\n"
|
prompt += f"你{self.personality_info}\n"
|
||||||
|
|
||||||
prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{message_stream_info}\n"
|
prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{message_stream_info}\n"
|
||||||
if related_memory_info:
|
# if related_memory_info:
|
||||||
prompt += f"你想起来{related_memory_info}。"
|
# prompt += f"你想起来{related_memory_info}。"
|
||||||
prompt += f"刚刚你的想法是{current_thinking_info}。"
|
prompt += f"刚刚你的想法是{current_thinking_info}。"
|
||||||
prompt += f"你现在看到了网友们发的新消息:{message_new_info}\n"
|
prompt += f"你现在看到了网友们发的新消息:{message_new_info}\n"
|
||||||
prompt += f"你刚刚回复了群友们:{reply_info}"
|
prompt += f"你刚刚回复了群友们:{reply_info}"
|
||||||
|
|||||||
Reference in New Issue
Block a user