我要曹飞一切之thinkflow创世纪

This commit is contained in:
SengokuCola
2025-03-24 00:23:17 +08:00
parent 9860ea085e
commit 6da66e74f6
9 changed files with 189 additions and 147 deletions

View File

@@ -1,47 +1,60 @@
from .outer_world import outer_world
import asyncio
from .offline_llm import LLMModel
from src.plugins.moods.moods import MoodManager
from src.plugins.models.utils_model import LLM_request
from src.plugins.chat.config import global_config
class CuttentState:
def __init__(self):
self.willing = 0
self.mood = 'TODO'
self.current_state_info = ""
class InnerWorld:
def __init__(self):
self.inner_world_info = ""
self.current_state : CuttentState = CuttentState()
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 BRain:
class SubHeartflow:
def __init__(self):
self.current_mind = ""
self.past_mind = []
self.inner_world = InnerWorld()
self.llm_model = LLMModel("Pro/Qwen/Qwen2.5-7B-Instruct")
self.current_state : CuttentState = CuttentState()
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.observe_chat_id = None
if not self.current_mind:
self.current_mind = "是麦麦,曾经是一个学习地质的女大学生,现在学习心理学和脑科学,你会刷贴吧,你现在正在浏览qq群想着qq群里发生的事情人们在谈论什么以及和你有什么关系你应该怎样在qq群中回复和发言。现在请麦麦你继续思考"
self.current_mind = "什么也没想"
def assign_observe(self,stream_id):
self.outer_world = outer_world.get_world_by_stream_id(stream_id)
self.observe_chat_id = stream_id
async def brain_start_working(self):
async def subheartflow_start_working(self):
while True:
await self.do_a_thinking()
await asyncio.sleep(10)
await asyncio.sleep(30)
async def do_a_thinking(self):
print("麦麦脑袋转起来了")
current_thinking = self.current_mind
outer_world_info = self.build_outer_world_info()
inner_world_info = self.build_inner_world_info(self.inner_world)
current_state_info = self.build_current_state_info(self.inner_world.current_state)
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'
message_stream_info = self.outer_world.talking_summary
# prompt += f"这是你当前的脑内状态{current_state_info}\n\n"
prompt = f"这是你刚刚接触的内容:{outer_world_info}\n\n"
# prompt += f"这是你当前的脑内状态{inner_world_info}\n\n"
prompt += f"这是你之前的想法{current_thinking}\n\n"
prompt += f"现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,注重当前的思考:"
prompt = f""
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"现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白,不要太长,但是记得结合上述的消息,要记得你的人设,关注聊天和新内容,不要思考太多:"
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
@@ -52,19 +65,25 @@ class BRain:
async def do_after_reply(self,reply_content,chat_talking_prompt):
print("麦麦脑袋转起来了")
current_thinking = self.current_mind
outer_world_info = self.build_outer_world_info()
inner_world_info = self.build_inner_world_info(self.inner_world)
current_state_info = self.build_current_state_info(self.inner_world.current_state)
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'
message_stream_info = self.outer_world.talking_summary
message_new_info = chat_talking_prompt
reply_info = reply_content
# prompt += f"这是你当前的脑内状态{current_state_info}\n\n"
prompt = f"这是你刚刚接触的内容:{outer_world_info}\n\n"
# prompt += f"这是你当前的脑内状态{inner_world_info}\n\n"
prompt += f"这是你之前想要回复的内容:{chat_talking_prompt}\n\n"
prompt += f"这是你之前的想法{current_thinking}\n\n"
prompt += f"这是你自己刚刚回复的内容{reply_content}\n\n"
prompt += f"现在你接下去继续思考,产生新的想法,不要分点输出,输出连贯的内心独白:"
prompt = f""
prompt += f"{personality_info}\n"
prompt += f"现在你正在上网和qq群里的网友们聊天群里正在聊的话题是{message_stream_info}\n"
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 += f"现在你接下去继续思考,产生新的想法,记得保留你刚刚的想法,不要分点输出,输出连贯的内心独白,不要太长,但是记得结合上述的消息,要记得你的人设,关注聊天和新内容,以及你回复的内容,不要思考太多:"
reponse, reasoning_content = await self.llm_model.generate_response_async(prompt)
@@ -72,18 +91,7 @@ class BRain:
self.current_mind = reponse
print(f"麦麦的脑内状态:{self.current_mind}")
def update_current_state_from_current_mind(self):
self.inner_world.current_state.willing += 0.01
def build_current_state_info(self,current_state):
current_state_info = current_state.current_state_info
return current_state_info
def build_inner_world_info(self,inner_world):
inner_world_info = inner_world.inner_world_info
return inner_world_info
def build_outer_world_info(self):
outer_world_info = outer_world.outer_world_info
@@ -94,16 +102,5 @@ class BRain:
self.current_mind = reponse
brain = BRain()
async def main():
# 创建两个任务
brain_task = asyncio.create_task(brain.brain_start_working())
outer_world_task = asyncio.create_task(outer_world.open_eyes())
# 等待两个任务
await asyncio.gather(brain_task, outer_world_task)
if __name__ == "__main__":
asyncio.run(main())
# subheartflow = SubHeartflow()