Merge pull request #582 from MaiM-with-u/think_flow_test
fix 思维流不会自动停止消耗token
This commit is contained in:
@@ -4,6 +4,7 @@ from src.plugins.moods.moods import MoodManager
|
|||||||
from src.plugins.models.utils_model import LLM_request
|
from src.plugins.models.utils_model import LLM_request
|
||||||
from src.plugins.chat.config import global_config
|
from src.plugins.chat.config import global_config
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
class CuttentState:
|
class CuttentState:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.willing = 0
|
self.willing = 0
|
||||||
@@ -29,6 +30,8 @@ class SubHeartflow:
|
|||||||
|
|
||||||
self.observe_chat_id = None
|
self.observe_chat_id = None
|
||||||
|
|
||||||
|
self.last_reply_time = time.time()
|
||||||
|
|
||||||
if not self.current_mind:
|
if not self.current_mind:
|
||||||
self.current_mind = "你什么也没想"
|
self.current_mind = "你什么也没想"
|
||||||
|
|
||||||
@@ -38,10 +41,14 @@ class SubHeartflow:
|
|||||||
|
|
||||||
async def subheartflow_start_working(self):
|
async def subheartflow_start_working(self):
|
||||||
while True:
|
while True:
|
||||||
await self.do_a_thinking()
|
current_time = time.time()
|
||||||
print("麦麦闹情绪了")
|
if current_time - self.last_reply_time > 180: # 3分钟 = 180秒
|
||||||
await self.judge_willing()
|
# print(f"{self.observe_chat_id}麦麦已经3分钟没有回复了,暂时停止思考")
|
||||||
await asyncio.sleep(30)
|
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):
|
async def do_a_thinking(self):
|
||||||
print("麦麦小脑袋转起来了")
|
print("麦麦小脑袋转起来了")
|
||||||
@@ -99,6 +106,8 @@ class SubHeartflow:
|
|||||||
self.current_mind = reponse
|
self.current_mind = reponse
|
||||||
print(f"{self.observe_chat_id}麦麦的脑内状态:{self.current_mind}")
|
print(f"{self.observe_chat_id}麦麦的脑内状态:{self.current_mind}")
|
||||||
|
|
||||||
|
self.last_reply_time = time.time()
|
||||||
|
|
||||||
async def judge_willing(self):
|
async def judge_willing(self):
|
||||||
# print("麦麦闹情绪了1")
|
# print("麦麦闹情绪了1")
|
||||||
personality_info = open("src/think_flow_demo/personality_info.txt", "r", encoding="utf-8").read()
|
personality_info = open("src/think_flow_demo/personality_info.txt", "r", encoding="utf-8").read()
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Heartflow:
|
|||||||
|
|
||||||
async def heartflow_start_working(self):
|
async def heartflow_start_working(self):
|
||||||
while True:
|
while True:
|
||||||
await self.do_a_thinking()
|
# await self.do_a_thinking()
|
||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
async def do_a_thinking(self):
|
async def do_a_thinking(self):
|
||||||
@@ -82,7 +82,7 @@ class Heartflow:
|
|||||||
|
|
||||||
prompt = ""
|
prompt = ""
|
||||||
prompt += f"{personality_info}\n"
|
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"现在麦麦在qq群里进行聊天,聊天的话题如下:{minds_str}\n"
|
||||||
prompt += f"你现在{mood_info}\n"
|
prompt += f"你现在{mood_info}\n"
|
||||||
prompt += '''现在请你总结这些聊天内容,注意关注聊天内容对原有的想法的影响,输出连贯的内心独白
|
prompt += '''现在请你总结这些聊天内容,注意关注聊天内容对原有的想法的影响,输出连贯的内心独白
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ enable = true
|
|||||||
|
|
||||||
[experimental]
|
[experimental]
|
||||||
enable_friend_chat = false # 是否启用好友聊天
|
enable_friend_chat = false # 是否启用好友聊天
|
||||||
enable_think_flow = false # 是否启用思维流
|
enable_think_flow = false # 是否启用思维流 注意:可能会消耗大量token,请谨慎开启
|
||||||
|
|
||||||
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env.prod自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
#下面的模型若使用硅基流动则不需要更改,使用ds官方则改成.env.prod自定义的宏,使用自定义模型则选择定位相似的模型自己填写
|
||||||
#推理模型
|
#推理模型
|
||||||
|
|||||||
Reference in New Issue
Block a user