Merge pull request #582 from MaiM-with-u/think_flow_test

fix 思维流不会自动停止消耗token
This commit is contained in:
SengokuCola
2025-03-26 12:54:29 +08:00
committed by GitHub
3 changed files with 16 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ from src.plugins.moods.moods import MoodManager
from src.plugins.models.utils_model import LLM_request
from src.plugins.chat.config import global_config
import re
import time
class CuttentState:
def __init__(self):
self.willing = 0
@@ -29,6 +30,8 @@ class SubHeartflow:
self.observe_chat_id = None
self.last_reply_time = time.time()
if not self.current_mind:
self.current_mind = "你什么也没想"
@@ -38,10 +41,14 @@ class SubHeartflow:
async def subheartflow_start_working(self):
while True:
await self.do_a_thinking()
print("麦麦闹情绪了")
await self.judge_willing()
await asyncio.sleep(30)
current_time = time.time()
if current_time - self.last_reply_time > 180: # 3分钟 = 180秒
# print(f"{self.observe_chat_id}麦麦已经3分钟没有回复了暂时停止思考")
await asyncio.sleep(25) # 每30秒检查一次
else:
await self.do_a_thinking()
await self.judge_willing()
await asyncio.sleep(25)
async def do_a_thinking(self):
print("麦麦小脑袋转起来了")
@@ -99,6 +106,8 @@ class SubHeartflow:
self.current_mind = reponse
print(f"{self.observe_chat_id}麦麦的脑内状态:{self.current_mind}")
self.last_reply_time = time.time()
async def judge_willing(self):
# print("麦麦闹情绪了1")
personality_info = open("src/think_flow_demo/personality_info.txt", "r", encoding="utf-8").read()

View File

@@ -30,7 +30,7 @@ class Heartflow:
async def heartflow_start_working(self):
while True:
await self.do_a_thinking()
# await self.do_a_thinking()
await asyncio.sleep(60)
async def do_a_thinking(self):
@@ -82,7 +82,7 @@ class Heartflow:
prompt = ""
prompt += f"{personality_info}\n"
prompt += f"现在麦麦的想法是:{self.current_mind}\n"
prompt += f"现在{global_config.BOT_NICKNAME}的想法是:{self.current_mind}\n"
prompt += f"现在麦麦在qq群里进行聊天聊天的话题如下{minds_str}\n"
prompt += f"你现在{mood_info}\n"
prompt += '''现在请你总结这些聊天内容,注意关注聊天内容对原有的想法的影响,输出连贯的内心独白

View File

@@ -132,7 +132,7 @@ enable = true
[experimental]
enable_friend_chat = false # 是否启用好友聊天
enable_think_flow = false # 是否启用思维流
enable_think_flow = false # 是否启用思维流 注意可能会消耗大量token请谨慎开启
#下面的模型若使用硅基流动则不需要更改使用ds官方则改成.env.prod自定义的宏使用自定义模型则选择定位相似的模型自己填写
#推理模型