feat:移除willing_amlifier,简化活跃度配置

This commit is contained in:
SengokuCola
2025-08-08 22:54:40 +08:00
parent 721546fff9
commit 59ac6713b1
6 changed files with 86 additions and 70 deletions

View File

@@ -700,7 +700,7 @@ class HeartFChatting:
"兴趣"模式下,判断是否回复并生成内容。
"""
interested_rate = (message_data.get("interest_value") or 0.0) * global_config.chat.willing_amplifier
interested_rate = message_data.get("interest_value") or 0.0
self.willing_manager.setup(message_data, self.chat_stream)

View File

@@ -261,9 +261,9 @@ class ExpressionSelector:
# 4. 调用LLM
try:
start_time = time.time()
# start_time = time.time()
content, (reasoning_content, model_name, _) = await self.llm_model.generate_response_async(prompt=prompt)
logger.info(f"LLM请求时间: {model_name} {time.time() - start_time} \n{prompt}")
# logger.info(f"LLM请求时间: {model_name} {time.time() - start_time} \n{prompt}")
# logger.info(f"模型名称: {model_name}")
# logger.info(f"LLM返回结果: {content}")

View File

@@ -21,7 +21,6 @@ class ClassicalWillingManager(BaseWillingManager):
self._decay_task = asyncio.create_task(self._decay_reply_willing())
async def get_reply_probability(self, message_id):
# sourcery skip: inline-immediately-returned-variable
willing_info = self.ongoing_messages[message_id]
chat_id = willing_info.chat_id
current_willing = self.chat_reply_willing.get(chat_id, 0)
@@ -32,8 +31,7 @@ class ClassicalWillingManager(BaseWillingManager):
# print(f"[{chat_id}] 兴趣值: {interested_rate}")
if interested_rate > 0.2:
current_willing += interested_rate - 0.2
current_willing += interested_rate
if willing_info.is_mentioned_bot and global_config.chat.mentioned_bot_inevitable_reply and current_willing < 2:
current_willing += 1 if current_willing < 1.0 else 0.2

View File

@@ -69,7 +69,6 @@ class ChatConfig(ConfigBase):
max_context_size: int = 18
"""上下文长度"""
willing_amplifier: float = 1.0
replyer_random_probability: float = 0.5
"""
@@ -89,26 +88,27 @@ class ChatConfig(ConfigBase):
at_bot_inevitable_reply: bool = False
"""@bot 必然回复"""
# 修改:基于时段的回复频率配置,改为数组格式
time_based_talk_frequency: list[str] = field(default_factory=lambda: [])
"""
基于时段的回复频率配置(全局)
格式:["HH:MM,frequency", "HH:MM,frequency", ...]
示例:["8:00,1", "12:00,2", "18:00,1.5", "00:00,0.5"]
表示从该时间开始使用该频率,直到下一个时间点
"""
# 新增:基于聊天流的个性化时段频率配置
# 合并后的时段频率配置
talk_frequency_adjust: list[list[str]] = field(default_factory=lambda: [])
"""
基于聊天流的个性化时段频率配置
统一的时段频率配置
格式:[["platform:chat_id:type", "HH:MM,frequency", "HH:MM,frequency", ...], ...]
示例:[
["qq:1026294844:group", "12:20,1", "16:10,2", "20:10,1", "00:10,0.3"],
["qq:729957033:group", "8:20,1", "12:10,2", "20:10,1.5", "00:10,0.2"]
全局配置示例:
[["", "8:00,1", "12:00,2", "18:00,1.5", "00:00,0.5"]]
特定聊天流配置示例:
[
["", "8:00,1", "12:00,1.2", "18:00,1.5", "01:00,0.6"], # 全局默认配置
["qq:1026294844:group", "12:20,1", "16:10,2", "20:10,1", "00:10,0.3"], # 特定群聊配置
["qq:729957033:private", "8:20,1", "12:10,2", "20:10,1.5", "00:10,0.2"] # 特定私聊配置
]
每个子列表的第一个元素是聊天流标识符,后续元素是"时间,频率"格式
表示从该时间开始使用该频率,直到下一个时间点
说明:
- 当第一个元素为空字符串""时,表示全局默认配置
- 当第一个元素为"platform:id:type"格式时,表示特定聊天流配置
- 后续元素是"时间,频率"格式,表示从该时间开始使用该频率,直到下一个时间点
- 优先级:特定聊天流配置 > 全局配置 > 默认 talk_frequency
"""
focus_value: float = 1.0
@@ -124,15 +124,17 @@ class ChatConfig(ConfigBase):
Returns:
float: 对应的频率值
"""
if not self.talk_frequency_adjust:
return self.talk_frequency
# 优先检查聊天流特定的配置
if chat_stream_id and self.talk_frequency_adjust:
if chat_stream_id:
stream_frequency = self._get_stream_specific_frequency(chat_stream_id)
if stream_frequency is not None:
return stream_frequency
# 如果没有聊天流特定配置,检查全局时段配置
if self.time_based_talk_frequency:
global_frequency = self._get_time_based_frequency(self.time_based_talk_frequency)
# 检查全局时段配置(第一个元素为空字符串的配置)
global_frequency = self._get_global_frequency()
if global_frequency is not None:
return global_frequency
@@ -253,6 +255,23 @@ class ChatConfig(ConfigBase):
except (ValueError, IndexError):
return None
def _get_global_frequency(self) -> Optional[float]:
"""
获取全局默认频率配置
Returns:
float: 频率值,如果没有配置则返回 None
"""
for config_item in self.talk_frequency_adjust:
if not config_item or len(config_item) < 2:
continue
# 检查是否为全局默认配置(第一个元素为空字符串)
if config_item[0] == "":
return self._get_time_based_frequency(config_item[1:])
return None
@dataclass
class MessageReceiveConfig(ConfigBase):

View File

@@ -106,10 +106,9 @@ class NoReplyAction(BaseAction):
# 获取当前聊天频率和意愿系数
talk_frequency = global_config.chat.get_current_talk_frequency(self.chat_id)
willing_amplifier = global_config.chat.willing_amplifier
# 计算调整后的阈值
adjusted_threshold = self._interest_exit_threshold / talk_frequency / willing_amplifier
adjusted_threshold = self._interest_exit_threshold / talk_frequency
logger.info(f"{self.log_prefix} 最近三次兴趣度总和: {total_recent_interest:.2f}, 调整后阈值: {adjusted_threshold:.2f}")
@@ -148,7 +147,7 @@ class NoReplyAction(BaseAction):
for msg_dict in recent_messages_dict:
interest_value = msg_dict.get("interest_value", 0.0)
if msg_dict.get("processed_plain_text", ""):
total_interest += interest_value * global_config.chat.willing_amplifier
total_interest += interest_value
# 记录到最近兴趣度列表
NoReplyAction._recent_interest_records.append(total_interest)
@@ -198,7 +197,7 @@ class NoReplyAction(BaseAction):
# 检查消息数量是否达到阈值
talk_frequency = global_config.chat.get_current_talk_frequency(self.chat_id)
modified_exit_count_threshold = (exit_message_count_threshold / talk_frequency) / global_config.chat.willing_amplifier
modified_exit_count_threshold = exit_message_count_threshold / talk_frequency
if new_message_count >= modified_exit_count_threshold:
# 记录兴趣度到列表
@@ -206,7 +205,7 @@ class NoReplyAction(BaseAction):
for msg_dict in recent_messages_dict:
interest_value = msg_dict.get("interest_value", 0.0)
if msg_dict.get("processed_plain_text", ""):
total_interest += interest_value * global_config.chat.willing_amplifier
total_interest += interest_value
NoReplyAction._recent_interest_records.append(total_interest)
@@ -228,7 +227,7 @@ class NoReplyAction(BaseAction):
text = msg_dict.get("processed_plain_text", "")
interest_value = msg_dict.get("interest_value", 0.0)
if text:
accumulated_interest += interest_value * global_config.chat.willing_amplifier
accumulated_interest += interest_value
# 只在兴趣值变化时输出log
if not hasattr(self, "_last_accumulated_interest") or accumulated_interest != self._last_accumulated_interest:

View File

@@ -1,15 +1,14 @@
[inner]
version = "6.0.0"
version = "6.1.0"
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
#如果你想要修改配置文件,请在修改后将version的值进行变更
#如果你想要修改配置文件,请递增version的值
#如果新增项目请阅读src/config/official_configs.py中的说明
#
# 版本格式:主版本号.次版本号.修订号,版本号递增规则如下:
# 主版本号:当你做了不兼容的 API 修改,
# 次版本号:当你做了向下兼容的功能性新增,
# 修订号:当你做了向下兼容的问题修正。
# 先行版本号及版本编译信息可以加到"主版本号.次版本号.修订号"的后面,作为延伸。
# 主版本号:MMC版本更新
# 次版本号:配置文件内容大更新
# 修订号:配置文件内容小更新
#----以上是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
[bot]
@@ -35,7 +34,13 @@ compress_identity = true # 是否压缩身份,压缩后会精简身份信息
enable_expression = true # 是否启用表达方式
# 描述麦麦说话的表达风格,表达习惯,例如:(请回复的平淡一些,简短一些,说中文,不要刻意突出自身学科背景。)
expression_style = "回复可以简短一些。可以参考贴吧,知乎和微博的回复风格,回复不要浮夸,不要用夸张修辞,平淡一些。"
enable_expression_learning = false # 是否启用表达学习,麦麦会学习不同群里人类说话风格(群之间不互通)
expression_learning = [ # 允许表达学习的聊天流列表,留空为全部允许
# "qq:1919810:private",
# "qq:114514:private",
# "qq:1111111:group",
]
learning_interval = 350 # 学习间隔 单位秒
expression_groups = [
@@ -55,7 +60,7 @@ focus_value = 1
# 麦麦的专注思考能力越高越容易专注可能消耗更多token
# 专注时能更好把握发言时机,能够进行持久的连续对话
willing_amplifier = 1 # 麦麦回复意愿
talk_frequency = 1 # 麦麦活跃度,越高,麦麦回复越频繁
max_context_size = 25 # 上下文长度
thinking_timeout = 40 # 麦麦一次回复最长思考规划时间超过这个时间的思考会放弃往往是api反应太慢
@@ -64,32 +69,29 @@ replyer_random_probability = 0.5 # 首要replyer模型被选择的概率
mentioned_bot_inevitable_reply = true # 提及 bot 大概率回复
at_bot_inevitable_reply = true # @bot 或 提及bot 大概率回复
talk_frequency = 1 # 麦麦回复频率,越高,麦麦回复越频繁
time_based_talk_frequency = ["8:00,1", "12:00,1.2", "18:00,1.5", "01:00,0.6"]
# 基于时段的回复频率配置(可选)
# 格式time_based_talk_frequency = ["HH:MM,frequency", ...]
# 示例:
# time_based_talk_frequency = ["8:00,1", "12:00,1.2", "18:00,1.5", "00:00,0.6"]
# 说明:表示从该时间开始使用该频率,直到下一个时间点
# 注意:如果没有配置,则使用上面的默认 talk_frequency 值
talk_frequency_adjust = [
["", "8:00,1", "12:00,1.2", "18:00,1.5", "01:00,0.6"],
["qq:114514:group", "12:20,1", "16:10,2", "20:10,1", "00:10,0.3"],
["qq:1919810:private", "8:20,1", "12:10,2", "20:10,1.5", "00:10,0.2"]
]
# 基于聊天流的个性化时段频率配置(可选)
# 格式:talk_frequency_adjust = [["platform:id:type", "HH:MM,frequency", ...], ...]
# 基于聊天流的个性化活跃度配置
# 格式:[["platform:chat_id:type", "HH:MM,frequency", "HH:MM,frequency", ...], ...]
# 全局配置示例:
# [["", "8:00,1", "12:00,2", "18:00,1.5", "00:00,0.5"]]
# 特定聊天流配置示例:
# [
# ["", "8:00,1", "12:00,1.2", "18:00,1.5", "01:00,0.6"], # 全局默认配置
# ["qq:1026294844:group", "12:20,1", "16:10,2", "20:10,1", "00:10,0.3"], # 特定群聊配置
# ["qq:729957033:private", "8:20,1", "12:10,2", "20:10,1.5", "00:10,0.2"] # 特定私聊配置
# ]
# 说明:
# - 第一个元素是聊天流标识符,格式为 "platform:id:type"
# - platform: 平台名称(如 qq
# - id: 群号或用户QQ号
# - type: group表示群聊private表示私聊
# - 后续元素是"时间,频率"格式,表示从该时间开始使用该频率,直到下一个时间点
# - 优先级:聊天流特定配置 > 全局时段配置 > 默认 talk_frequency
# - 时间支持跨天,例如 "00:10,0.3" 表示从凌晨0:10开始使用频率0.3
# - 系统会自动将 "platform:id:type" 转换为内部的哈希chat_id进行匹配
# - 第一个元素为空字符串""时,表示全局默认配置
# - 当第一个元素为"platform:id:type"格式时,表示特定聊天流配置
# - 后续元素是"时间,频率"格式,表示从该时间开始使用该活跃度,直到下一个时间点
# - 优先级:特定聊天流配置 > 全局配置 > 默认 talk_frequency
[message_receive]
# 以下是消息过滤,可以根据规则过滤特定消息,将不会读取这些消息
@@ -109,6 +111,10 @@ willing_mode = "classical" # 回复意愿模式 —— 经典模式classical
[tool]
enable_tool = false # 是否在普通聊天中启用工具
[mood]
enable_mood = true # 是否启用情绪系统
mood_update_threshold = 1 # 情绪更新阈值,越高,更新越慢
[emoji]
emoji_chance = 0.6 # 麦麦激活表情包动作的概率
emoji_activate_type = "random" # 表情包激活类型可选randomllm ; random下表情包动作随机启用llm下表情包动作根据llm判断是否启用
@@ -144,10 +150,6 @@ memory_ban_words = [ "表情包", "图片", "回复", "聊天记录" ]
[voice]
enable_asr = false # 是否启用语音识别,启用后麦麦可以识别语音消息,启用该功能需要配置语音识别模型[model.voice]s
[mood]
enable_mood = true # 是否启用情绪系统
mood_update_threshold = 1 # 情绪更新阈值,越高,更新越慢
[lpmm_knowledge] # lpmm知识库配置
enable = false # 是否启用lpmm知识库
rag_synonym_search_top_k = 10 # 同义词搜索TopK
@@ -183,8 +185,6 @@ regex_rules = [
[custom_prompt]
image_prompt = "请用中文描述这张图片的内容。如果有文字请把文字描述概括出来请留意其主题直观感受输出为一段平文本最多30字请注意不要分点就输出一段文本"
[response_post_process]
enable_response_post_process = true # 是否启用回复后处理,包括错别字生成器,回复分割器