From 3c4f492b76d9a42eb6c637290bccbd6abead86ff Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Wed, 26 Mar 2025 12:51:39 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=80=9D=E7=BB=B4=E6=B5=81=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E8=87=AA=E5=8A=A8=E5=81=9C=E6=AD=A2=E6=B6=88=E8=80=97?= =?UTF-8?q?token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/think_flow_demo/current_mind.py | 17 +++++++++++++---- src/think_flow_demo/heartflow.py | 4 ++-- template/bot_config_template.toml | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/think_flow_demo/current_mind.py b/src/think_flow_demo/current_mind.py index 78447215f..6facdbf9b 100644 --- a/src/think_flow_demo/current_mind.py +++ b/src/think_flow_demo/current_mind.py @@ -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() diff --git a/src/think_flow_demo/heartflow.py b/src/think_flow_demo/heartflow.py index c2e32d602..45843e490 100644 --- a/src/think_flow_demo/heartflow.py +++ b/src/think_flow_demo/heartflow.py @@ -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 += '''现在请你总结这些聊天内容,注意关注聊天内容对原有的想法的影响,输出连贯的内心独白 diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index e025df46c..6591d4272 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -132,7 +132,7 @@ enable = true [experimental] enable_friend_chat = false # 是否启用好友聊天 -enable_think_flow = false # 是否启用思维流 +enable_think_flow = false # 是否启用思维流 注意:可能会消耗大量token,请谨慎开启 #下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env.prod自定义的宏,使用自定义模型则选择定位相似的模型自己填写 #推理模型