fix:优化激活值,优化logger显示
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .current_mind import SubHeartflow
|
||||
from .sub_heartflow import SubHeartflow
|
||||
from src.plugins.moods.moods import MoodManager
|
||||
from src.plugins.models.utils_model import LLM_request
|
||||
from src.plugins.config.config import global_config, BotConfig
|
||||
@@ -46,7 +46,7 @@ class Heartflow:
|
||||
logger.info("麦麦大脑袋转起来了")
|
||||
self.current_state.update_current_state_info()
|
||||
|
||||
personality_info = " ".join(BotConfig.PROMPT_PERSONALITY)
|
||||
personality_info = " ".join(global_config.PROMPT_PERSONALITY)
|
||||
current_thinking_info = self.current_mind
|
||||
mood_info = self.current_state.mood
|
||||
related_memory_info = 'memory'
|
||||
|
||||
@@ -16,6 +16,10 @@ class Talking_info:
|
||||
self.observe_times = 0
|
||||
self.activate = 360
|
||||
|
||||
self.last_summary_time = int(datetime.now().timestamp()) # 上次更新summary的时间
|
||||
self.summary_count = 0 # 30秒内的更新次数
|
||||
self.max_update_in_30s = 2
|
||||
|
||||
self.oberve_interval = 3
|
||||
|
||||
self.llm_summary = LLM_request(
|
||||
@@ -60,16 +64,22 @@ class Talking_info:
|
||||
if len(self.talking_message) > 20:
|
||||
self.talking_message = self.talking_message[-20:] # 只保留最新的20条
|
||||
self.translate_message_list_to_str()
|
||||
# print(self.talking_message_str)
|
||||
self.observe_times += 1
|
||||
self.last_observe_time = new_messages[-1]["time"]
|
||||
|
||||
if self.observe_times > 3:
|
||||
# 检查是否需要更新summary
|
||||
current_time = int(datetime.now().timestamp())
|
||||
if current_time - self.last_summary_time >= 30: # 如果超过30秒,重置计数
|
||||
self.summary_count = 0
|
||||
self.last_summary_time = current_time
|
||||
|
||||
if self.summary_count < self.max_update_in_30s: # 如果30秒内更新次数小于2次
|
||||
await self.update_talking_summary()
|
||||
# print(f"更新了聊天总结:{self.talking_summary}")
|
||||
self.summary_count += 1
|
||||
|
||||
async def update_talking_summary(self):
|
||||
#基于已经有的talking_summary,和新的talking_message,生成一个summary
|
||||
# print(f"更新聊天总结:{self.talking_summary}")
|
||||
prompt = ""
|
||||
prompt = f"你正在参与一个qq群聊的讨论,这个群之前在聊的内容是:{self.talking_summary}\n"
|
||||
prompt += f"现在群里的群友们产生了新的讨论,有了新的发言,具体内容如下:{self.talking_message_str}\n"
|
||||
|
||||
@@ -6,6 +6,16 @@ from src.plugins.config.config import global_config, BotConfig
|
||||
import re
|
||||
import time
|
||||
from src.plugins.schedule.schedule_generator import bot_schedule
|
||||
from src.plugins.memory_system.Hippocampus import HippocampusManager
|
||||
from src.common.logger import get_module_logger, LogConfig, SUB_HEARTFLOW_STYLE_CONFIG # noqa: E402
|
||||
|
||||
subheartflow_config = LogConfig(
|
||||
# 使用海马体专用样式
|
||||
console_format=SUB_HEARTFLOW_STYLE_CONFIG["console_format"],
|
||||
file_format=SUB_HEARTFLOW_STYLE_CONFIG["file_format"],
|
||||
)
|
||||
logger = get_module_logger("subheartflow", config=subheartflow_config)
|
||||
|
||||
|
||||
class CuttentState:
|
||||
def __init__(self):
|
||||
@@ -37,7 +47,7 @@ class SubHeartflow:
|
||||
if not self.current_mind:
|
||||
self.current_mind = "你什么也没想"
|
||||
|
||||
self.personality_info = " ".join(BotConfig.PROMPT_PERSONALITY)
|
||||
self.personality_info = " ".join(global_config.PROMPT_PERSONALITY)
|
||||
|
||||
def assign_observe(self,stream_id):
|
||||
self.outer_world = outer_world.get_world_by_stream_id(stream_id)
|
||||
@@ -55,23 +65,42 @@ class SubHeartflow:
|
||||
await asyncio.sleep(60)
|
||||
|
||||
async def do_a_thinking(self):
|
||||
print("麦麦小脑袋转起来了")
|
||||
self.current_state.update_current_state_info()
|
||||
|
||||
current_thinking_info = self.current_mind
|
||||
mood_info = self.current_state.mood
|
||||
related_memory_info = ''
|
||||
|
||||
message_stream_info = self.outer_world.talking_summary
|
||||
schedule_info = bot_schedule.get_current_num_task(num = 2,time_info = False)
|
||||
print(f"message_stream_info:{message_stream_info}")
|
||||
|
||||
related_memory = await HippocampusManager.get_instance().get_memory_from_text(
|
||||
text=message_stream_info,
|
||||
max_memory_num=3,
|
||||
max_memory_length=2,
|
||||
max_depth=3,
|
||||
fast_retrieval=False
|
||||
)
|
||||
# print(f"相关记忆:{related_memory}")
|
||||
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"你刚刚在做的事情是:{schedule_info}\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"
|
||||
prompt += f"你想起来{related_memory_info}。"
|
||||
if related_memory_info:
|
||||
prompt += f"你想起来{related_memory_info}。"
|
||||
prompt += f"刚刚你的想法是{current_thinking_info}。"
|
||||
prompt += f"你现在{mood_info}。"
|
||||
prompt += f"你现在{mood_info}。\n"
|
||||
prompt += "现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,"
|
||||
prompt += "但是记得结合上述的消息,要记得维持住你的人设,关注聊天和新内容,不要思考太多:"
|
||||
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
|
||||
@@ -79,7 +108,8 @@ class SubHeartflow:
|
||||
self.update_current_mind(reponse)
|
||||
|
||||
self.current_mind = reponse
|
||||
print(f"麦麦的脑内状态:{self.current_mind}")
|
||||
print(prompt)
|
||||
logger.info(f"麦麦的脑内状态:{self.current_mind}")
|
||||
|
||||
async def do_after_reply(self,reply_content,chat_talking_prompt):
|
||||
# print("麦麦脑袋转起来了")
|
||||
@@ -91,24 +121,29 @@ class SubHeartflow:
|
||||
message_stream_info = self.outer_world.talking_summary
|
||||
message_new_info = chat_talking_prompt
|
||||
reply_info = reply_content
|
||||
schedule_info = bot_schedule.get_current_num_task(num = 1,time_info = False)
|
||||
|
||||
|
||||
prompt = ""
|
||||
prompt += f"{self.personality_info}\n"
|
||||
prompt += f"你刚刚在做的事情是:{schedule_info}\n"
|
||||
prompt += f"你{self.personality_info}\n"
|
||||
|
||||
prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{message_stream_info}\n"
|
||||
prompt += f"你想起来{related_memory_info}。"
|
||||
if related_memory_info:
|
||||
prompt += f"你想起来{related_memory_info}。"
|
||||
prompt += f"刚刚你的想法是{current_thinking_info}。"
|
||||
prompt += f"你现在看到了网友们发的新消息:{message_new_info}\n"
|
||||
prompt += f"你刚刚回复了群友们:{reply_info}"
|
||||
prompt += f"你现在{mood_info}。"
|
||||
prompt += "现在你接下去继续思考,产生新的想法,记得保留你刚刚的想法,不要分点输出,输出连贯的内心独白"
|
||||
prompt += "不要太长,但是记得结合上述的消息,要记得你的人设,关注聊天和新内容,以及你回复的内容,不要思考太多:"
|
||||
prompt += "不要太长,但是记得结合上述的消息,要记得你的人设,关注聊天和新内容,关注你回复的内容,不要思考太多:"
|
||||
|
||||
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
|
||||
|
||||
self.update_current_mind(reponse)
|
||||
|
||||
self.current_mind = reponse
|
||||
print(f"{self.observe_chat_id}麦麦的脑内状态:{self.current_mind}")
|
||||
logger.info(f"麦麦回复后的脑内状态:{self.current_mind}")
|
||||
|
||||
self.last_reply_time = time.time()
|
||||
|
||||
@@ -133,7 +168,7 @@ class SubHeartflow:
|
||||
else:
|
||||
self.current_state.willing = 0
|
||||
|
||||
print(f"{self.observe_chat_id}麦麦的回复意愿:{self.current_state.willing}")
|
||||
logger.info(f"{self.observe_chat_id}麦麦的回复意愿:{self.current_state.willing}")
|
||||
|
||||
return self.current_state.willing
|
||||
|
||||
Reference in New Issue
Block a user