fix:修改config
This commit is contained in:
@@ -186,12 +186,18 @@ class BotConfig:
|
|||||||
ban_words = set()
|
ban_words = set()
|
||||||
ban_msgs_regex = set()
|
ban_msgs_regex = set()
|
||||||
|
|
||||||
# heartflow
|
# [heartflow] # 启用启用heart_flowC(心流聊天)模式时生效, 需要填写token消耗量巨大的相关模型
|
||||||
# enable_heartflow: bool = False # 是否启用心流
|
# 启用后麦麦会自主选择进入heart_flowC模式(持续一段时间), 进行长时间高质量的聊天
|
||||||
sub_heart_flow_update_interval: int = 60 # 子心流更新频率,间隔 单位秒
|
enable_heart_flowC: bool = True # 是否启用heart_flowC(心流聊天, HFC)模式
|
||||||
sub_heart_flow_freeze_time: int = 120 # 子心流冻结时间,超过这个时间没有回复,子心流会冻结,间隔 单位秒
|
reply_trigger_threshold: float = 3.0 # 心流聊天触发阈值,越低越容易触发
|
||||||
|
probability_decay_factor_per_second: float = 0.2 # 概率衰减因子,越大衰减越快
|
||||||
|
default_decay_rate_per_second: float = 0.98 # 默认衰减率,越大衰减越慢
|
||||||
|
initial_duration: int = 60 # 初始持续时间,越大心流聊天持续的时间越长
|
||||||
|
|
||||||
|
# sub_heart_flow_update_interval: int = 60 # 子心流更新频率,间隔 单位秒
|
||||||
|
# sub_heart_flow_freeze_time: int = 120 # 子心流冻结时间,超过这个时间没有回复,子心流会冻结,间隔 单位秒
|
||||||
sub_heart_flow_stop_time: int = 600 # 子心流停止时间,超过这个时间没有回复,子心流会停止,间隔 单位秒
|
sub_heart_flow_stop_time: int = 600 # 子心流停止时间,超过这个时间没有回复,子心流会停止,间隔 单位秒
|
||||||
heart_flow_update_interval: int = 300 # 心流更新频率,间隔 单位秒
|
# heart_flow_update_interval: int = 300 # 心流更新频率,间隔 单位秒
|
||||||
observation_context_size: int = 20 # 心流观察到的最长上下文大小,超过这个值的上下文会被压缩
|
observation_context_size: int = 20 # 心流观察到的最长上下文大小,超过这个值的上下文会被压缩
|
||||||
compressed_length: int = 5 # 不能大于observation_context_size,心流上下文压缩的最短压缩长度,超过心流观察到的上下文长度,会压缩,最短压缩长度为5
|
compressed_length: int = 5 # 不能大于observation_context_size,心流上下文压缩的最短压缩长度,超过心流观察到的上下文长度,会压缩,最短压缩长度为5
|
||||||
compress_length_limit: int = 5 # 最多压缩份数,超过该数值的压缩上下文会被删除
|
compress_length_limit: int = 5 # 最多压缩份数,超过该数值的压缩上下文会被删除
|
||||||
@@ -207,8 +213,8 @@ class BotConfig:
|
|||||||
|
|
||||||
# response
|
# response
|
||||||
response_mode: str = "heart_flow" # 回复策略
|
response_mode: str = "heart_flow" # 回复策略
|
||||||
MODEL_R1_PROBABILITY: float = 0.8 # R1模型概率
|
model_reasoning_probability: float = 0.7 # 麦麦回答时选择推理模型(主要)模型概率
|
||||||
MODEL_V3_PROBABILITY: float = 0.1 # V3模型概率
|
model_normal_probability: float = 0.3 # 麦麦回答时选择一般模型(次要)模型概率
|
||||||
# MODEL_R1_DISTILL_PROBABILITY: float = 0.1 # R1蒸馏模型概率
|
# MODEL_R1_DISTILL_PROBABILITY: float = 0.1 # R1蒸馏模型概率
|
||||||
|
|
||||||
# emoji
|
# emoji
|
||||||
@@ -401,29 +407,32 @@ class BotConfig:
|
|||||||
|
|
||||||
def response(parent: dict):
|
def response(parent: dict):
|
||||||
response_config = parent["response"]
|
response_config = parent["response"]
|
||||||
config.MODEL_R1_PROBABILITY = response_config.get("model_r1_probability", config.MODEL_R1_PROBABILITY)
|
config.model_reasoning_probability = response_config.get("model_reasoning_probability", config.model_reasoning_probability)
|
||||||
config.MODEL_V3_PROBABILITY = response_config.get("model_v3_probability", config.MODEL_V3_PROBABILITY)
|
config.model_normal_probability = response_config.get("model_normal_probability", config.model_normal_probability)
|
||||||
# config.MODEL_R1_DISTILL_PROBABILITY = response_config.get(
|
|
||||||
# "model_r1_distill_probability", config.MODEL_R1_DISTILL_PROBABILITY
|
|
||||||
# )
|
# 添加 enable_heart_flowC 的加载逻辑 (假设它在 [response] 部分)
|
||||||
config.max_response_length = response_config.get("max_response_length", config.max_response_length)
|
if config.INNER_VERSION in SpecifierSet(">=1.4.0"):
|
||||||
if config.INNER_VERSION in SpecifierSet(">=1.0.4"):
|
config.enable_heart_flowC = response_config.get("enable_heart_flowC", config.enable_heart_flowC)
|
||||||
config.response_mode = response_config.get("response_mode", config.response_mode)
|
|
||||||
|
|
||||||
def heartflow(parent: dict):
|
def heartflow(parent: dict):
|
||||||
heartflow_config = parent["heartflow"]
|
heartflow_config = parent["heartflow"]
|
||||||
config.sub_heart_flow_update_interval = heartflow_config.get(
|
# 加载新增的 heartflowC 参数
|
||||||
"sub_heart_flow_update_interval", config.sub_heart_flow_update_interval
|
|
||||||
)
|
|
||||||
config.sub_heart_flow_freeze_time = heartflow_config.get(
|
# 加载原有的 heartflow 参数
|
||||||
"sub_heart_flow_freeze_time", config.sub_heart_flow_freeze_time
|
# config.sub_heart_flow_update_interval = heartflow_config.get(
|
||||||
)
|
# "sub_heart_flow_update_interval", config.sub_heart_flow_update_interval
|
||||||
|
# )
|
||||||
|
# config.sub_heart_flow_freeze_time = heartflow_config.get(
|
||||||
|
# "sub_heart_flow_freeze_time", config.sub_heart_flow_freeze_time
|
||||||
|
# )
|
||||||
config.sub_heart_flow_stop_time = heartflow_config.get(
|
config.sub_heart_flow_stop_time = heartflow_config.get(
|
||||||
"sub_heart_flow_stop_time", config.sub_heart_flow_stop_time
|
"sub_heart_flow_stop_time", config.sub_heart_flow_stop_time
|
||||||
)
|
)
|
||||||
config.heart_flow_update_interval = heartflow_config.get(
|
# config.heart_flow_update_interval = heartflow_config.get(
|
||||||
"heart_flow_update_interval", config.heart_flow_update_interval
|
# "heart_flow_update_interval", config.heart_flow_update_interval
|
||||||
)
|
# )
|
||||||
if config.INNER_VERSION in SpecifierSet(">=1.3.0"):
|
if config.INNER_VERSION in SpecifierSet(">=1.3.0"):
|
||||||
config.observation_context_size = heartflow_config.get(
|
config.observation_context_size = heartflow_config.get(
|
||||||
"observation_context_size", config.observation_context_size
|
"observation_context_size", config.observation_context_size
|
||||||
@@ -432,6 +441,11 @@ class BotConfig:
|
|||||||
config.compress_length_limit = heartflow_config.get(
|
config.compress_length_limit = heartflow_config.get(
|
||||||
"compress_length_limit", config.compress_length_limit
|
"compress_length_limit", config.compress_length_limit
|
||||||
)
|
)
|
||||||
|
if config.INNER_VERSION in SpecifierSet(">=1.4.0"):
|
||||||
|
config.reply_trigger_threshold = heartflow_config.get("reply_trigger_threshold", config.reply_trigger_threshold)
|
||||||
|
config.probability_decay_factor_per_second = heartflow_config.get("probability_decay_factor_per_second", config.probability_decay_factor_per_second)
|
||||||
|
config.default_decay_rate_per_second = heartflow_config.get("default_decay_rate_per_second", config.default_decay_rate_per_second)
|
||||||
|
config.initial_duration = heartflow_config.get("initial_duration", config.initial_duration)
|
||||||
|
|
||||||
def willing(parent: dict):
|
def willing(parent: dict):
|
||||||
willing_config = parent["willing"]
|
willing_config = parent["willing"]
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from .sub_heartflow import SubHeartflow
|
from .sub_heartflow import SubHeartflow, ChattingObservation
|
||||||
from .observation import ChattingObservation
|
|
||||||
from src.plugins.moods.moods import MoodManager
|
from src.plugins.moods.moods import MoodManager
|
||||||
from src.plugins.models.utils_model import LLMRequest
|
from src.plugins.models.utils_model import LLMRequest
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
@@ -10,7 +9,8 @@ from src.common.logger import get_module_logger, LogConfig, HEARTFLOW_STYLE_CONF
|
|||||||
from src.individuality.individuality import Individuality
|
from src.individuality.individuality import Individuality
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any, Optional
|
||||||
|
import traceback
|
||||||
|
|
||||||
heartflow_config = LogConfig(
|
heartflow_config = LogConfig(
|
||||||
# 使用海马体专用样式
|
# 使用海马体专用样式
|
||||||
@@ -70,20 +70,27 @@ class Heartflow:
|
|||||||
"""定期清理不活跃的子心流"""
|
"""定期清理不活跃的子心流"""
|
||||||
while True:
|
while True:
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
inactive_subheartflows = []
|
inactive_subheartflows_ids = [] # 修改变量名以清晰表示存储的是ID
|
||||||
|
|
||||||
# 检查所有子心流
|
# 检查所有子心流
|
||||||
for subheartflow_id, subheartflow in self._subheartflows.items():
|
# 使用 list(self._subheartflows.items()) 避免在迭代时修改字典
|
||||||
|
for subheartflow_id, subheartflow in list(self._subheartflows.items()):
|
||||||
if (
|
if (
|
||||||
current_time - subheartflow.last_active_time > global_config.sub_heart_flow_stop_time
|
current_time - subheartflow.last_active_time > global_config.sub_heart_flow_stop_time
|
||||||
): # 10分钟 = 600秒
|
): # 10分钟 = 600秒
|
||||||
inactive_subheartflows.append(subheartflow_id)
|
logger.info(f"发现不活跃的子心流: {subheartflow_id}, 准备清理。")
|
||||||
logger.info(f"发现不活跃的子心流: {subheartflow_id}")
|
# 1. 标记子心流让其后台任务停止
|
||||||
|
subheartflow.should_stop = True
|
||||||
|
# 2. 将ID添加到待清理列表
|
||||||
|
inactive_subheartflows_ids.append(subheartflow_id)
|
||||||
|
|
||||||
# 清理不活跃的子心流
|
# 清理不活跃的子心流 (从字典中移除)
|
||||||
for subheartflow_id in inactive_subheartflows:
|
for subheartflow_id in inactive_subheartflows_ids:
|
||||||
del self._subheartflows[subheartflow_id]
|
if subheartflow_id in self._subheartflows:
|
||||||
logger.info(f"已清理不活跃的子心流: {subheartflow_id}")
|
del self._subheartflows[subheartflow_id]
|
||||||
|
logger.info(f"已从主心流移除子心流: {subheartflow_id}")
|
||||||
|
else:
|
||||||
|
logger.warning(f"尝试移除子心流 {subheartflow_id} 时发现其已被移除。")
|
||||||
|
|
||||||
await asyncio.sleep(30) # 每分钟检查一次
|
await asyncio.sleep(30) # 每分钟检查一次
|
||||||
|
|
||||||
@@ -95,8 +102,10 @@ class Heartflow:
|
|||||||
await asyncio.sleep(30) # 每分钟检查一次是否有新的子心流
|
await asyncio.sleep(30) # 每分钟检查一次是否有新的子心流
|
||||||
continue
|
continue
|
||||||
|
|
||||||
await self.do_a_thinking()
|
# await self.do_a_thinking()
|
||||||
await asyncio.sleep(global_config.heart_flow_update_interval * 3) # 5分钟思考一次
|
# await asyncio.sleep(global_config.heart_flow_update_interval * 3) # 5分钟思考一次
|
||||||
|
|
||||||
|
await asyncio.sleep(300)
|
||||||
|
|
||||||
async def heartflow_start_working(self):
|
async def heartflow_start_working(self):
|
||||||
# 启动清理任务
|
# 启动清理任务
|
||||||
@@ -216,33 +225,55 @@ class Heartflow:
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def create_subheartflow(self, subheartflow_id):
|
async def create_subheartflow(self, subheartflow_id: Any) -> Optional[SubHeartflow]:
|
||||||
"""
|
|
||||||
创建一个新的SubHeartflow实例
|
|
||||||
添加一个SubHeartflow实例到self._subheartflows字典中
|
|
||||||
并根据subheartflow_id为子心流创建一个观察对象
|
|
||||||
"""
|
"""
|
||||||
|
获取或创建一个新的SubHeartflow实例。
|
||||||
|
|
||||||
|
如果实例已存在,则直接返回。
|
||||||
|
如果不存在,则创建实例、观察对象、启动后台任务,并返回新实例。
|
||||||
|
创建过程中发生任何错误将返回 None。
|
||||||
|
|
||||||
|
Args:
|
||||||
|
subheartflow_id: 用于标识子心流的ID (例如群聊ID)。
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
对应的 SubHeartflow 实例,如果创建失败则返回 None。
|
||||||
|
"""
|
||||||
|
# 检查是否已存在
|
||||||
|
existing_subheartflow = self._subheartflows.get(subheartflow_id)
|
||||||
|
if existing_subheartflow:
|
||||||
|
logger.debug(f"返回已存在的 subheartflow: {subheartflow_id}")
|
||||||
|
return existing_subheartflow
|
||||||
|
|
||||||
|
# 如果不存在,则创建新的
|
||||||
|
logger.info(f"尝试创建新的 subheartflow: {subheartflow_id}")
|
||||||
try:
|
try:
|
||||||
if subheartflow_id not in self._subheartflows:
|
subheartflow = SubHeartflow(subheartflow_id)
|
||||||
subheartflow = SubHeartflow(subheartflow_id)
|
|
||||||
# 创建一个观察对象,目前只可以用chat_id创建观察对象
|
# 创建并初始化观察对象
|
||||||
logger.debug(f"创建 observation: {subheartflow_id}")
|
logger.debug(f"为 {subheartflow_id} 创建 observation")
|
||||||
observation = ChattingObservation(subheartflow_id)
|
observation = ChattingObservation(subheartflow_id)
|
||||||
await observation.initialize()
|
await observation.initialize() # 等待初始化完成
|
||||||
subheartflow.add_observation(observation)
|
subheartflow.add_observation(observation)
|
||||||
logger.debug("添加 observation 成功")
|
logger.debug(f"为 {subheartflow_id} 添加 observation 成功")
|
||||||
# 创建异步任务
|
|
||||||
asyncio.create_task(subheartflow.subheartflow_start_working())
|
# 创建并存储后台任务
|
||||||
logger.debug("创建异步任务 成功")
|
subheartflow.task = asyncio.create_task(subheartflow.subheartflow_start_working())
|
||||||
self._subheartflows[subheartflow_id] = subheartflow
|
logger.debug(f"为 {subheartflow_id} 创建后台任务成功")
|
||||||
logger.info("添加 subheartflow 成功")
|
|
||||||
return self._subheartflows[subheartflow_id]
|
# 添加到管理字典
|
||||||
|
self._subheartflows[subheartflow_id] = subheartflow
|
||||||
|
logger.info(f"添加 subheartflow {subheartflow_id} 成功")
|
||||||
|
return subheartflow
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"创建 subheartflow 失败: {e}")
|
# 记录详细错误信息
|
||||||
|
logger.error(f"创建 subheartflow {subheartflow_id} 失败: {e}")
|
||||||
|
logger.error(traceback.format_exc()) # 记录完整的 traceback
|
||||||
|
# 考虑是否需要更具体的错误处理或资源清理逻辑
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_subheartflow(self, observe_chat_id) -> SubHeartflow:
|
def get_subheartflow(self, observe_chat_id: Any) -> Optional[SubHeartflow]:
|
||||||
"""获取指定ID的SubHeartflow实例"""
|
"""获取指定ID的SubHeartflow实例"""
|
||||||
return self._subheartflows.get(observe_chat_id)
|
return self._subheartflows.get(observe_chat_id)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from src.plugins.moods.moods import MoodManager
|
|||||||
from src.plugins.models.utils_model import LLMRequest
|
from src.plugins.models.utils_model import LLMRequest
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
import time
|
import time
|
||||||
from typing import Optional
|
from typing import Optional, List
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import traceback
|
import traceback
|
||||||
from src.plugins.chat.utils import parse_text_timestamps
|
from src.plugins.chat.utils import parse_text_timestamps
|
||||||
@@ -65,7 +65,7 @@ class SubHeartflow:
|
|||||||
def __init__(self, subheartflow_id):
|
def __init__(self, subheartflow_id):
|
||||||
self.subheartflow_id = subheartflow_id
|
self.subheartflow_id = subheartflow_id
|
||||||
|
|
||||||
self.current_mind = ""
|
self.current_mind = "你什么也没想"
|
||||||
self.past_mind = []
|
self.past_mind = []
|
||||||
self.current_state: CurrentState = CurrentState()
|
self.current_state: CurrentState = CurrentState()
|
||||||
self.llm_model = LLMRequest(
|
self.llm_model = LLMRequest(
|
||||||
@@ -76,16 +76,14 @@ class SubHeartflow:
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.main_heartflow_info = ""
|
self.main_heartflow_info = ""
|
||||||
|
|
||||||
self.last_reply_time = time.time()
|
|
||||||
self.last_active_time = time.time() # 添加最后激活时间
|
self.last_active_time = time.time() # 添加最后激活时间
|
||||||
|
self.should_stop = False # 添加停止标志
|
||||||
if not self.current_mind:
|
self.task: Optional[asyncio.Task] = None # 添加 task 属性
|
||||||
self.current_mind = "你什么也没想"
|
|
||||||
|
|
||||||
self.is_active = False
|
self.is_active = False
|
||||||
|
|
||||||
self.observations: list[ChattingObservation] = []
|
self.observations: List[ChattingObservation] = [] # 使用 List 类型提示
|
||||||
|
|
||||||
self.running_knowledges = []
|
self.running_knowledges = []
|
||||||
|
|
||||||
@@ -93,20 +91,14 @@ class SubHeartflow:
|
|||||||
|
|
||||||
async def subheartflow_start_working(self):
|
async def subheartflow_start_working(self):
|
||||||
while True:
|
while True:
|
||||||
current_time = time.time()
|
|
||||||
# --- 调整后台任务逻辑 --- #
|
# --- 调整后台任务逻辑 --- #
|
||||||
# 这个后台循环现在主要负责检查是否需要自我销毁
|
# 这个后台循环现在主要负责检查是否需要自我销毁
|
||||||
# 不再主动进行思考或状态更新,这些由 HeartFC_Chat 驱动
|
# 不再主动进行思考或状态更新,这些由 HeartFC_Chat 驱动
|
||||||
|
|
||||||
# 检查是否超过指定时间没有激活 (例如,没有被调用进行思考)
|
# 检查是否被主心流标记为停止
|
||||||
if current_time - self.last_active_time > global_config.sub_heart_flow_stop_time: # 例如 5 分钟
|
if self.should_stop:
|
||||||
logger.info(
|
logger.info(f"子心流 {self.subheartflow_id} 被标记为停止,正在退出后台任务...")
|
||||||
f"子心流 {self.subheartflow_id} 超过 {global_config.sub_heart_flow_stop_time} 秒没有激活,正在销毁..."
|
break # 退出循环以停止任务
|
||||||
f" (Last active: {datetime.fromtimestamp(self.last_active_time).strftime('%Y-%m-%d %H:%M:%S')})"
|
|
||||||
)
|
|
||||||
# 在这里添加实际的销毁逻辑,例如从主 Heartflow 管理器中移除自身
|
|
||||||
# heartflow.remove_subheartflow(self.subheartflow_id) # 假设有这样的方法
|
|
||||||
break # 退出循环以停止任务
|
|
||||||
|
|
||||||
await asyncio.sleep(global_config.sub_heart_flow_update_interval) # 定期检查销毁条件
|
await asyncio.sleep(global_config.sub_heart_flow_update_interval) # 定期检查销毁条件
|
||||||
|
|
||||||
|
|||||||
@@ -105,53 +105,26 @@ class ChatBot:
|
|||||||
template_group_name = None
|
template_group_name = None
|
||||||
|
|
||||||
async def preprocess():
|
async def preprocess():
|
||||||
if global_config.enable_pfc_chatting:
|
if groupinfo is None:
|
||||||
try:
|
if global_config.enable_friend_chat:
|
||||||
if groupinfo is None:
|
if global_config.enable_pfc_chatting:
|
||||||
if global_config.enable_friend_chat:
|
userinfo = message.message_info.user_info
|
||||||
userinfo = message.message_info.user_info
|
messageinfo = message.message_info
|
||||||
messageinfo = message.message_info
|
# 创建聊天流
|
||||||
# 创建聊天流
|
chat = await chat_manager.get_or_create_stream(
|
||||||
chat = await chat_manager.get_or_create_stream(
|
platform=messageinfo.platform,
|
||||||
platform=messageinfo.platform,
|
user_info=userinfo,
|
||||||
user_info=userinfo,
|
group_info=groupinfo,
|
||||||
group_info=groupinfo,
|
)
|
||||||
)
|
message.update_chat_stream(chat)
|
||||||
message.update_chat_stream(chat)
|
await self.only_process_chat.process_message(message)
|
||||||
await self.only_process_chat.process_message(message)
|
await self._create_pfc_chat(message)
|
||||||
await self._create_pfc_chat(message)
|
|
||||||
else:
|
else:
|
||||||
if groupinfo.group_id in global_config.talk_allowed_groups:
|
await self.heartFC_processor.process_message(message_data)
|
||||||
# logger.debug(f"开始群聊模式{str(message_data)[:50]}...")
|
|
||||||
if global_config.response_mode == "heart_flow":
|
|
||||||
# logger.info(f"启动最新最好的思维流FC模式{str(message_data)[:50]}...")
|
|
||||||
await self.heartFC_processor.process_message(message_data)
|
|
||||||
elif global_config.response_mode == "reasoning":
|
|
||||||
# logger.debug(f"开始推理模式{str(message_data)[:50]}...")
|
|
||||||
await self.reasoning_chat.process_message(message_data)
|
|
||||||
else:
|
|
||||||
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"处理PFC消息失败: {e}")
|
|
||||||
else:
|
else:
|
||||||
if groupinfo is None:
|
await self.heartFC_processor.process_message(message_data)
|
||||||
if global_config.enable_friend_chat:
|
|
||||||
# 私聊处理流程
|
|
||||||
# await self._handle_private_chat(message)
|
|
||||||
if global_config.response_mode == "heart_flow":
|
|
||||||
await self.heartFC_processor.process_message(message_data)
|
|
||||||
elif global_config.response_mode == "reasoning":
|
|
||||||
await self.reasoning_chat.process_message(message_data)
|
|
||||||
else:
|
|
||||||
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
|
||||||
else: # 群聊处理
|
|
||||||
if groupinfo.group_id in global_config.talk_allowed_groups:
|
|
||||||
if global_config.response_mode == "heart_flow":
|
|
||||||
await self.heartFC_processor.process_message(message_data)
|
|
||||||
elif global_config.response_mode == "reasoning":
|
|
||||||
await self.reasoning_chat.process_message(message_data)
|
|
||||||
else:
|
|
||||||
logger.error(f"未知的回复模式,请检查配置文件!!: {global_config.response_mode}")
|
|
||||||
|
|
||||||
if template_group_name:
|
if template_group_name:
|
||||||
async with global_prompt_manager.async_message_scope(template_group_name):
|
async with global_prompt_manager.async_message_scope(template_group_name):
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ from src.config.config import global_config
|
|||||||
from src.plugins.chat.utils_image import image_path_to_base64 # Local import needed after move
|
from src.plugins.chat.utils_image import image_path_to_base64 # Local import needed after move
|
||||||
from src.plugins.utils.timer_calculater import Timer # <--- Import Timer
|
from src.plugins.utils.timer_calculater import Timer # <--- Import Timer
|
||||||
|
|
||||||
|
INITIAL_DURATION = 60.0
|
||||||
|
|
||||||
|
|
||||||
# 定义日志配置 (使用 loguru 格式)
|
# 定义日志配置 (使用 loguru 格式)
|
||||||
interest_log_config = LogConfig(
|
interest_log_config = LogConfig(
|
||||||
console_format=PFC_STYLE_CONFIG["console_format"], # 使用默认控制台格式
|
console_format=PFC_STYLE_CONFIG["console_format"], # 使用默认控制台格式
|
||||||
@@ -91,7 +94,7 @@ class PFChatting:
|
|||||||
self._loop_active: bool = False # Is the loop currently running?
|
self._loop_active: bool = False # Is the loop currently running?
|
||||||
self._loop_task: Optional[asyncio.Task] = None # Stores the main loop task
|
self._loop_task: Optional[asyncio.Task] = None # Stores the main loop task
|
||||||
self._trigger_count_this_activation: int = 0 # Counts triggers within an active period
|
self._trigger_count_this_activation: int = 0 # Counts triggers within an active period
|
||||||
self._initial_duration: float = 60.0 # 首次触发增加的时间
|
self._initial_duration: float = INITIAL_DURATION # 首次触发增加的时间
|
||||||
self._last_added_duration: float = self._initial_duration # <--- 新增:存储上次增加的时间
|
self._last_added_duration: float = self._initial_duration # <--- 新增:存储上次增加的时间
|
||||||
|
|
||||||
def _get_log_prefix(self) -> str:
|
def _get_log_prefix(self) -> str:
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
[inner]
|
[inner]
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
|
||||||
|
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
||||||
#以下是给开发人员阅读的,一般用户不需要阅读
|
|
||||||
#如果你想要修改配置文件,请在修改后将version的值进行变更
|
#如果你想要修改配置文件,请在修改后将version的值进行变更
|
||||||
#如果新增项目,请在BotConfig类下新增相应的变量
|
#如果新增项目,请在BotConfig类下新增相应的变量
|
||||||
#1.如果你修改的是[]层级项目,例如你新增了 [memory],那么请在config.py的 load_config函数中的include_configs字典中新增"内容":{
|
#1.如果你修改的是[]层级项目,例如你新增了 [memory],那么请在config.py的 load_config函数中的include_configs字典中新增"内容":{
|
||||||
@@ -19,11 +18,12 @@ version = "1.4.0"
|
|||||||
# 次版本号:当你做了向下兼容的功能性新增,
|
# 次版本号:当你做了向下兼容的功能性新增,
|
||||||
# 修订号:当你做了向下兼容的问题修正。
|
# 修订号:当你做了向下兼容的问题修正。
|
||||||
# 先行版本号及版本编译信息可以加到“主版本号.次版本号.修订号”的后面,作为延伸。
|
# 先行版本号及版本编译信息可以加到“主版本号.次版本号.修订号”的后面,作为延伸。
|
||||||
|
#----以上是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
||||||
|
|
||||||
[bot]
|
[bot]
|
||||||
qq = 114514
|
qq = 1145141919810
|
||||||
nickname = "麦麦"
|
nickname = "麦麦"
|
||||||
alias_names = ["麦叠", "牢麦"]
|
alias_names = ["麦叠", "牢麦"] #该选项还在调试中,暂时未生效
|
||||||
|
|
||||||
[groups]
|
[groups]
|
||||||
talk_allowed = [
|
talk_allowed = [
|
||||||
@@ -41,23 +41,24 @@ personality_sides = [
|
|||||||
"用一句话或几句话描述人格的一些细节",
|
"用一句话或几句话描述人格的一些细节",
|
||||||
"用一句话或几句话描述人格的一些细节",
|
"用一句话或几句话描述人格的一些细节",
|
||||||
"用一句话或几句话描述人格的一些细节",
|
"用一句话或几句话描述人格的一些细节",
|
||||||
]# 条数任意
|
]# 条数任意,不能为0, 该选项还在调试中,可能未完全生效
|
||||||
|
|
||||||
[identity] #アイデンティティがない 生まれないらららら
|
[identity] #アイデンティティがない 生まれないらららら
|
||||||
# 兴趣爱好 未完善,有些条目未使用
|
# 兴趣爱好 未完善,有些条目未使用
|
||||||
identity_detail = [
|
identity_detail = [
|
||||||
"身份特点",
|
"身份特点",
|
||||||
"身份特点",
|
"身份特点",
|
||||||
]# 条数任意
|
]# 条数任意,不能为0, 该选项还在调试中,可能未完全生效
|
||||||
#外貌特征
|
#外貌特征
|
||||||
height = 170 # 身高 单位厘米
|
height = 170 # 身高 单位厘米 该选项还在调试中,暂时未生效
|
||||||
weight = 50 # 体重 单位千克
|
weight = 50 # 体重 单位千克 该选项还在调试中,暂时未生效
|
||||||
age = 20 # 年龄 单位岁
|
age = 20 # 年龄 单位岁 该选项还在调试中,暂时未生效
|
||||||
gender = "男" # 性别
|
gender = "男" # 性别 该选项还在调试中,暂时未生效
|
||||||
appearance = "用几句话描述外貌特征" # 外貌特征
|
appearance = "用几句话描述外貌特征" # 外貌特征 该选项还在调试中,暂时未生效
|
||||||
|
|
||||||
[schedule]
|
[schedule]
|
||||||
enable_schedule_gen = true # 是否启用日程表(尚未完成)
|
enable_schedule_gen = true # 是否启用日程表
|
||||||
|
enable_schedule_interaction = true # 日程表是否影响回复模式
|
||||||
prompt_schedule_gen = "用几句话描述描述性格特点或行动规律,这个特征会用来生成日程表"
|
prompt_schedule_gen = "用几句话描述描述性格特点或行动规律,这个特征会用来生成日程表"
|
||||||
schedule_doing_update_interval = 900 # 日程表更新间隔 单位秒
|
schedule_doing_update_interval = 900 # 日程表更新间隔 单位秒
|
||||||
schedule_temperature = 0.1 # 日程表温度,建议0.1-0.5
|
schedule_temperature = 0.1 # 日程表温度,建议0.1-0.5
|
||||||
@@ -67,19 +68,25 @@ time_zone = "Asia/Shanghai" # 给你的机器人设置时区,可以解决运
|
|||||||
nonebot-qq="http://127.0.0.1:18002/api/message"
|
nonebot-qq="http://127.0.0.1:18002/api/message"
|
||||||
|
|
||||||
[response] #群聊的回复策略
|
[response] #群聊的回复策略
|
||||||
#reasoning:推理模式,麦麦会根据上下文进行推理,并给出回复
|
enable_heart_flowC = true
|
||||||
#heart_flow:结合了PFC模式和心流模式,麦麦会进行主动的观察和回复,并给出回复
|
# 该功能还在完善中
|
||||||
response_mode = "heart_flow" # 回复策略,可选值:heart_flow(心流),reasoning(推理)
|
# 是否启用heart_flowC(心流聊天,HFC)模式
|
||||||
|
# 启用后麦麦会自主选择进入heart_flowC模式(持续一段时间),进行主动的观察和回复,并给出回复,比较消耗token
|
||||||
|
|
||||||
#推理回复参数
|
#一般回复参数
|
||||||
model_r1_probability = 0.7 # 麦麦回答时选择主要回复模型1 模型的概率
|
model_reasoning_probability = 0.7 # 麦麦回答时选择推理模型 模型的概率
|
||||||
model_v3_probability = 0.3 # 麦麦回答时选择次要回复模型2 模型的概率
|
model_normal_probability = 0.3 # 麦麦回答时选择一般模型 模型的概率
|
||||||
|
|
||||||
|
[heartflow] #启用启用heart_flowC(心流聊天)模式时生效,需要填写以下参数
|
||||||
|
reply_trigger_threshold = 3.0 # 心流聊天触发阈值,越低越容易进入心流聊天
|
||||||
|
probability_decay_factor_per_second = 0.2 # 概率衰减因子,越大衰减越快,越高越容易退出心流聊天
|
||||||
|
default_decay_rate_per_second = 0.98 # 默认衰减率,越大衰减越快,越高越难进入心流聊天
|
||||||
|
initial_duration = 60 # 初始持续时间,越大心流聊天持续的时间越长
|
||||||
|
|
||||||
[heartflow] # 注意:可能会消耗大量token,请谨慎开启,仅会使用v3模型
|
|
||||||
sub_heart_flow_update_interval = 60 # 子心流更新频率,间隔 单位秒
|
|
||||||
sub_heart_flow_freeze_time = 100 # 子心流冻结时间,超过这个时间没有回复,子心流会冻结,间隔 单位秒
|
|
||||||
sub_heart_flow_stop_time = 500 # 子心流停止时间,超过这个时间没有回复,子心流会停止,间隔 单位秒
|
sub_heart_flow_stop_time = 500 # 子心流停止时间,超过这个时间没有回复,子心流会停止,间隔 单位秒
|
||||||
heart_flow_update_interval = 600 # 心流更新频率,间隔 单位秒
|
# sub_heart_flow_update_interval = 60
|
||||||
|
# sub_heart_flow_freeze_time = 100
|
||||||
|
# heart_flow_update_interval = 600
|
||||||
|
|
||||||
observation_context_size = 20 # 心流观察到的最长上下文大小,超过这个值的上下文会被压缩
|
observation_context_size = 20 # 心流观察到的最长上下文大小,超过这个值的上下文会被压缩
|
||||||
compressed_length = 5 # 不能大于observation_context_size,心流上下文压缩的最短压缩长度,超过心流观察到的上下文长度,会压缩,最短压缩长度为5
|
compressed_length = 5 # 不能大于observation_context_size,心流上下文压缩的最短压缩长度,超过心流观察到的上下文长度,会压缩,最短压缩长度为5
|
||||||
@@ -87,11 +94,13 @@ compress_length_limit = 5 #最多压缩份数,超过该数值的压缩上下
|
|||||||
|
|
||||||
|
|
||||||
[message]
|
[message]
|
||||||
max_context_size = 12 # 麦麦获得的上文数量,建议12,太短太长都会导致脑袋尖尖
|
max_context_size = 12 # 麦麦回复时获得的上文数量,建议12,太短太长都会导致脑袋尖尖
|
||||||
emoji_chance = 0.2 # 麦麦使用表情包的概率,设置为1让麦麦自己决定发不发
|
emoji_chance = 0.2 # 麦麦一般回复时使用表情包的概率,设置为1让麦麦自己决定发不发
|
||||||
thinking_timeout = 60 # 麦麦最长思考时间,超过这个时间的思考会放弃
|
thinking_timeout = 100 # 麦麦最长思考时间,超过这个时间的思考会放弃(往往是api反应太慢)
|
||||||
max_response_length = 256 # 麦麦回答的最大token数
|
max_response_length = 256 # 麦麦单次回答的最大token数
|
||||||
message_buffer = true # 启用消息缓冲器?启用此项以解决消息的拆分问题,但会使麦麦的回复延迟
|
message_buffer = true # 启用消息缓冲器?启用此项以解决消息的拆分问题,但会使麦麦的回复延迟
|
||||||
|
|
||||||
|
# 以下是消息过滤,可以根据规则过滤特定消息,将不会读取这些消息
|
||||||
ban_words = [
|
ban_words = [
|
||||||
# "403","张三"
|
# "403","张三"
|
||||||
]
|
]
|
||||||
@@ -103,22 +112,23 @@ ban_msgs_regex = [
|
|||||||
# "\\[CQ:at,qq=\\d+\\]" # 匹配@
|
# "\\[CQ:at,qq=\\d+\\]" # 匹配@
|
||||||
]
|
]
|
||||||
|
|
||||||
[willing]
|
[willing] # 一般回复模式的回复意愿设置
|
||||||
willing_mode = "classical" # 回复意愿模式 —— 经典模式:classical,动态模式:dynamic,mxp模式:mxp,自定义模式:custom(需要你自己实现)
|
willing_mode = "classical" # 回复意愿模式 —— 经典模式:classical,动态模式:dynamic,mxp模式:mxp,自定义模式:custom(需要你自己实现)
|
||||||
response_willing_amplifier = 1 # 麦麦回复意愿放大系数,一般为1
|
response_willing_amplifier = 1 # 麦麦回复意愿放大系数,一般为1
|
||||||
response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数,听到记忆里的内容时放大系数
|
response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数,听到记忆里的内容时放大系数
|
||||||
down_frequency_rate = 3 # 降低回复频率的群组回复意愿降低系数 除法
|
down_frequency_rate = 3 # 降低回复频率的群组回复意愿降低系数 除法
|
||||||
emoji_response_penalty = 0.1 # 表情包回复惩罚系数,设为0为不回复单个表情包,减少单独回复表情包的概率
|
emoji_response_penalty = 0 # 表情包回复惩罚系数,设为0为不回复单个表情包,减少单独回复表情包的概率
|
||||||
mentioned_bot_inevitable_reply = false # 提及 bot 必然回复
|
mentioned_bot_inevitable_reply = false # 提及 bot 必然回复
|
||||||
at_bot_inevitable_reply = false # @bot 必然回复
|
at_bot_inevitable_reply = false # @bot 必然回复
|
||||||
|
|
||||||
[emoji]
|
[emoji]
|
||||||
max_emoji_num = 120 # 表情包最大数量
|
max_emoji_num = 90 # 表情包最大数量
|
||||||
max_reach_deletion = true # 开启则在达到最大数量时删除表情包,关闭则达到最大数量时不删除,只是不会继续收集表情包
|
max_reach_deletion = true # 开启则在达到最大数量时删除表情包,关闭则达到最大数量时不删除,只是不会继续收集表情包
|
||||||
check_interval = 30 # 检查表情包(注册,破损,删除)的时间间隔(分钟)
|
check_interval = 30 # 检查表情包(注册,破损,删除)的时间间隔(分钟)
|
||||||
auto_save = true # 是否保存表情包和图片
|
auto_save = true # 是否保存表情包和图片
|
||||||
enable_check = false # 是否启用表情包过滤
|
|
||||||
check_prompt = "符合公序良俗" # 表情包过滤要求
|
enable_check = false # 是否启用表情包过滤,只有符合该要求的表情包才会被保存
|
||||||
|
check_prompt = "符合公序良俗" # 表情包过滤要求,只有符合该要求的表情包才会被保存
|
||||||
|
|
||||||
[memory]
|
[memory]
|
||||||
build_memory_interval = 2000 # 记忆构建间隔 单位秒 间隔越低,麦麦学习越多,但是冗余信息也会增多
|
build_memory_interval = 2000 # 记忆构建间隔 单位秒 间隔越低,麦麦学习越多,但是冗余信息也会增多
|
||||||
@@ -131,7 +141,8 @@ forget_memory_interval = 1000 # 记忆遗忘间隔 单位秒 间隔越低,
|
|||||||
memory_forget_time = 24 #多长时间后的记忆会被遗忘 单位小时
|
memory_forget_time = 24 #多长时间后的记忆会被遗忘 单位小时
|
||||||
memory_forget_percentage = 0.01 # 记忆遗忘比例 控制记忆遗忘程度 越大遗忘越多 建议保持默认
|
memory_forget_percentage = 0.01 # 记忆遗忘比例 控制记忆遗忘程度 越大遗忘越多 建议保持默认
|
||||||
|
|
||||||
memory_ban_words = [ #不希望记忆的词
|
#不希望记忆的词,已经记忆的不会受到影响
|
||||||
|
memory_ban_words = [
|
||||||
# "403","张三"
|
# "403","张三"
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -167,7 +178,7 @@ word_replace_rate=0.006 # 整词替换概率
|
|||||||
|
|
||||||
[response_splitter]
|
[response_splitter]
|
||||||
enable_response_splitter = true # 是否启用回复分割器
|
enable_response_splitter = true # 是否启用回复分割器
|
||||||
response_max_length = 100 # 回复允许的最大长度
|
response_max_length = 256 # 回复允许的最大长度
|
||||||
response_max_sentence_num = 4 # 回复允许的最大句子数
|
response_max_sentence_num = 4 # 回复允许的最大句子数
|
||||||
|
|
||||||
[remote] #发送统计信息,主要是看全球有多少只麦麦
|
[remote] #发送统计信息,主要是看全球有多少只麦麦
|
||||||
|
|||||||
Reference in New Issue
Block a user