feat 思维流大核+小核
This commit is contained in:
@@ -24,6 +24,8 @@ class SubHeartflow:
|
||||
self.llm_model = LLM_request(model=global_config.llm_topic_judge, temperature=0.7, max_tokens=600, request_type="sub_heart_flow")
|
||||
self.outer_world = None
|
||||
|
||||
self.main_heartflow_info = ""
|
||||
|
||||
self.observe_chat_id = None
|
||||
|
||||
if not self.current_mind:
|
||||
@@ -49,12 +51,13 @@ class SubHeartflow:
|
||||
message_stream_info = self.outer_world.talking_summary
|
||||
|
||||
prompt = f""
|
||||
# prompt += f"麦麦的总体想法是:{self.main_heartflow_info}\n\n"
|
||||
prompt += f"{personality_info}\n"
|
||||
prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{message_stream_info}\n"
|
||||
prompt += f"你想起来{related_memory_info}。"
|
||||
prompt += f"刚刚你的想法是{current_thinking_info}。"
|
||||
prompt += f"你现在{mood_info}。"
|
||||
prompt += f"现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,但是记得结合上述的消息,要记得你的人设,关注聊天和新内容,不要思考太多:"
|
||||
prompt += f"现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,但是记得结合上述的消息,要记得维持住你的人设,关注聊天和新内容,不要思考太多:"
|
||||
|
||||
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
|
||||
|
||||
|
||||
@@ -1,9 +1,95 @@
|
||||
from .current_mind import SubHeartflow
|
||||
from src.plugins.moods.moods import MoodManager
|
||||
from src.plugins.models.utils_model import LLM_request
|
||||
from src.plugins.chat.config import global_config
|
||||
from .outer_world import outer_world
|
||||
import asyncio
|
||||
|
||||
class SubHeartflowManager:
|
||||
class CuttentState:
|
||||
def __init__(self):
|
||||
self._subheartflows = {}
|
||||
self.willing = 0
|
||||
self.current_state_info = ""
|
||||
|
||||
self.mood_manager = MoodManager()
|
||||
self.mood = self.mood_manager.get_prompt()
|
||||
|
||||
def update_current_state_info(self):
|
||||
self.current_state_info = self.mood_manager.get_current_mood()
|
||||
|
||||
class Heartflow:
|
||||
def __init__(self):
|
||||
self.current_mind = "你什么也没想"
|
||||
self.past_mind = []
|
||||
self.current_state : CuttentState = CuttentState()
|
||||
self.llm_model = LLM_request(model=global_config.llm_topic_judge, temperature=0.6, max_tokens=1000, request_type="heart_flow")
|
||||
|
||||
self._subheartflows = {}
|
||||
self.active_subheartflows_nums = 0
|
||||
|
||||
|
||||
|
||||
async def heartflow_start_working(self):
|
||||
while True:
|
||||
await self.do_a_thinking()
|
||||
await asyncio.sleep(60)
|
||||
|
||||
async def do_a_thinking(self):
|
||||
print("麦麦大脑袋转起来了")
|
||||
self.current_state.update_current_state_info()
|
||||
|
||||
personality_info = open("src/think_flow_demo/personality_info.txt", "r", encoding="utf-8").read()
|
||||
current_thinking_info = self.current_mind
|
||||
mood_info = self.current_state.mood
|
||||
related_memory_info = 'memory'
|
||||
sub_flows_info = await self.get_all_subheartflows_minds()
|
||||
|
||||
prompt = ""
|
||||
prompt += f"{personality_info}\n"
|
||||
# prompt += f"现在你正在上网,和qq群里的网友们聊天,群里正在聊的话题是:{message_stream_info}\n"
|
||||
prompt += f"你想起来{related_memory_info}。"
|
||||
prompt += f"刚刚你的主要想法是{current_thinking_info}。"
|
||||
prompt += f"你还有一些小想法,因为你在参加不同的群聊天,是你正在做的事情:{sub_flows_info}\n"
|
||||
prompt += f"你现在{mood_info}。"
|
||||
prompt += f"现在你接下去继续思考,产生新的想法,但是要基于原有的主要想法,不要分点输出,输出连贯的内心独白,不要太长,但是记得结合上述的消息,关注新内容:"
|
||||
|
||||
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
|
||||
|
||||
self.update_current_mind(reponse)
|
||||
|
||||
self.current_mind = reponse
|
||||
print(f"麦麦的总体脑内状态:{self.current_mind}")
|
||||
|
||||
for _, subheartflow in self._subheartflows.items():
|
||||
subheartflow.main_heartflow_info = reponse
|
||||
|
||||
def update_current_mind(self,reponse):
|
||||
self.past_mind.append(self.current_mind)
|
||||
self.current_mind = reponse
|
||||
|
||||
|
||||
|
||||
async def get_all_subheartflows_minds(self):
|
||||
sub_minds = ""
|
||||
for _, subheartflow in self._subheartflows.items():
|
||||
sub_minds += subheartflow.current_mind
|
||||
|
||||
return await self.minds_summary(sub_minds)
|
||||
|
||||
async def minds_summary(self,minds_str):
|
||||
personality_info = open("src/think_flow_demo/personality_info.txt", "r", encoding="utf-8").read()
|
||||
mood_info = self.current_state.mood
|
||||
|
||||
prompt = ""
|
||||
prompt += f"{personality_info}\n"
|
||||
prompt += f"现在麦麦的想法是:{self.current_mind}\n"
|
||||
prompt += f"现在麦麦在qq群里进行聊天,聊天的话题如下:{minds_str}\n"
|
||||
prompt += f"你现在{mood_info}\n"
|
||||
prompt += f"现在请你总结这些聊天内容,注意关注聊天内容对原有的想法的影响,输出连贯的内心独白,不要太长,但是记得结合上述的消息,要记得你的人设,关注新内容:"
|
||||
|
||||
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
|
||||
|
||||
return reponse
|
||||
|
||||
def create_subheartflow(self, observe_chat_id):
|
||||
"""创建一个新的SubHeartflow实例"""
|
||||
if observe_chat_id not in self._subheartflows:
|
||||
@@ -17,5 +103,6 @@ class SubHeartflowManager:
|
||||
"""获取指定ID的SubHeartflow实例"""
|
||||
return self._subheartflows.get(observe_chat_id)
|
||||
|
||||
|
||||
# 创建一个全局的管理器实例
|
||||
subheartflow_manager = SubHeartflowManager()
|
||||
subheartflow_manager = Heartflow()
|
||||
|
||||
@@ -17,7 +17,7 @@ class Talking_info:
|
||||
self.observe_times = 0
|
||||
self.activate = 360
|
||||
|
||||
self.oberve_interval = 3
|
||||
self.oberve_interval = 5
|
||||
|
||||
self.llm_summary = LLM_request(model=global_config.llm_topic_judge, temperature=0.7, max_tokens=300, request_type="outer_world")
|
||||
|
||||
@@ -38,32 +38,35 @@ class Talking_info:
|
||||
"time": {"$gt": self.last_observe_time}
|
||||
})
|
||||
|
||||
if new_messages_count > 10:
|
||||
if new_messages_count > 15:
|
||||
self.activate = 360*(self.observe_times+1)
|
||||
return
|
||||
|
||||
await asyncio.sleep(10) # 每10秒检查一次
|
||||
|
||||
async def observe_world(self):
|
||||
# 查找新消息
|
||||
# 查找新消息,限制最多20条
|
||||
new_messages = list(db.messages.find({
|
||||
"chat_id": self.chat_id,
|
||||
"time": {"$gt": self.last_observe_time}
|
||||
}).sort("time", 1)) # 按时间正序排列
|
||||
}).sort("time", 1).limit(20)) # 按时间正序排列,最多20条
|
||||
|
||||
if not new_messages:
|
||||
self.activate += -1
|
||||
return
|
||||
|
||||
# 将新消息添加到talking_message
|
||||
# 将新消息添加到talking_message,同时保持列表长度不超过20条
|
||||
self.talking_message.extend(new_messages)
|
||||
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:
|
||||
await self.update_talking_summary()
|
||||
print(f"更新了聊天总结:{self.talking_summary}")
|
||||
# print(f"更新了聊天总结:{self.talking_summary}")
|
||||
|
||||
async def update_talking_summary(self):
|
||||
#基于已经有的talking_summary,和新的talking_message,生成一个summary
|
||||
|
||||
@@ -1 +1 @@
|
||||
你叫麦麦,你19岁,是一个大二的心理学和脑科女大学生,你有一头黑色短发,你会刷贴吧
|
||||
你叫麦麦,你19岁,是一个大二的女大学生,你有一头黑色短发,你会刷贴吧
|
||||
Reference in New Issue
Block a user