feat:移除willing_amlifier,简化活跃度配置
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,17 +124,19 @@ 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)
|
||||
if global_frequency is not None:
|
||||
return global_frequency
|
||||
# 检查全局时段配置(第一个元素为空字符串的配置)
|
||||
global_frequency = self._get_global_frequency()
|
||||
if global_frequency is not None:
|
||||
return global_frequency
|
||||
|
||||
# 如果都没有匹配,返回默认值
|
||||
return self.talk_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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user