炸飞了一点石山,将主动思考的id配置修改为分群聊/私聊的两个id配置然后增加了区分平台的功能

顺手改了一个注释的位置,它在的位置错了
应该在主动思考上面而不是下面的
This commit is contained in:
Furina-1013-create
2025-08-25 19:52:18 +08:00
parent 469e0f38a5
commit 8afb5b545d
3 changed files with 66 additions and 42 deletions

View File

@@ -140,7 +140,7 @@ class ProactiveThinker:
功能说明:
- 检查聊天流是否存在
- 检查当前聊天是否在启用列表中(如果配置了列表
- 检查当前聊天是否在启用列表中(按平台和类型分别检查
- 根据聊天类型(群聊/私聊)和配置决定是否启用
- 群聊需要proactive_thinking_in_group为True
- 私聊需要proactive_thinking_in_private为True
@@ -148,21 +148,35 @@ class ProactiveThinker:
if not self.context.chat_stream:
return False
try:
chat_id = int(self.context.stream_id.split(':')[-1])
except (ValueError, IndexError):
chat_id = None
proactive_thinking_ids = getattr(global_config.chat, 'proactive_thinking_enable_ids', [])
if proactive_thinking_ids and (chat_id is None or chat_id not in proactive_thinking_ids):
return False
is_group_chat = self.context.chat_stream.group_info is not None
# 检查基础开关
if is_group_chat and not global_config.chat.proactive_thinking_in_group:
return False
if not is_group_chat and not global_config.chat.proactive_thinking_in_private:
return False
# 获取当前聊天的完整标识 (platform:chat_id)
stream_parts = self.context.stream_id.split(':')
if len(stream_parts) >= 2:
platform = stream_parts[0]
chat_id = stream_parts[1]
current_chat_identifier = f"{platform}:{chat_id}"
else:
# 如果无法解析则使用原始stream_id
current_chat_identifier = self.context.stream_id
# 检查是否在启用列表中
if is_group_chat:
# 群聊检查
enable_list = getattr(global_config.chat, 'proactive_thinking_enable_in_groups', [])
if enable_list and current_chat_identifier not in enable_list:
return False
else:
# 私聊检查
enable_list = getattr(global_config.chat, 'proactive_thinking_enable_in_private', [])
if enable_list and current_chat_identifier not in enable_list:
return False
return True

View File

@@ -84,9 +84,9 @@ class ChatConfig(ValidatedConfigBase):
The_scope_that_proactive_thinking_can_trigger: str = Field(default="all", description="主动思考可以触发的范围")
proactive_thinking_in_private: bool = Field(default=True, description="主动思考可以在私聊里面启用")
proactive_thinking_in_group: bool = Field(default=True, description="主动思考可以在群聊里面启用")
proactive_thinking_enable_ids: List[int] = Field(default_factory=list, description="启用主动思考的范围,不区分群聊和私聊,为空则不限制")
proactive_thinking_enable_in_private: List[str] = Field(default_factory=list, description="启用主动思考的私聊范围,格式platform:user_id,为空则不限制")
proactive_thinking_enable_in_groups: List[str] = Field(default_factory=list, description="启用主动思考的群聊范围格式platform:group_id为空则不限制")
delta_sigma: int = Field(default=120, description="采用正态分布随机时间间隔")
enable_ids: List[int] = Field(default_factory=lambda: [123456, 234567], description="启用主动思考的范围,不区分群聊和私聊,为空则不限制")
proactive_thinking_prompt_template: str = Field(default="""现在群里面已经隔了{time}没有人发送消息了,请你结合上下文以及群聊里面之前聊过的话题和你的人设来决定要不要主动发送消息,你可以选择:
1. 继续保持沉默(当{time}以前已经结束了一个话题并且你不想挑起新话题时)

View File

@@ -127,36 +127,6 @@ talk_frequency_adjust = [
# 全局配置示例:
# [["", "8:00,1", "12:00,2", "18:00,1.5", "00:00,0.5"]]
# 主动思考功能配置仅在focus模式下生效
enable_proactive_thinking = false # 是否启用主动思考功能
proactive_thinking_interval = 1500 # 主动思考触发间隔时间默认1500秒25分钟
# TIPS:
# 创意玩法可以设置为0设置为0时将基于delta_sigma生成纯随机间隔
# 负数保险:如果设置为负数,会自动使用绝对值
proactive_thinking_in_private = true # 主动思考可以在私聊里面启用
proactive_thinking_in_group = true # 主动思考可以在群聊里面启用
proactive_thinking_enable_ids = [123456, 234567] # 启用主动思考的范围,不区分群聊和私聊,为空则不限制
delta_sigma = 120 # 正态分布的标准差,控制时间间隔的随机程度
# 特殊用法:
# - 设置为0禁用正态分布使用固定间隔
# - 设置得很大如6000产生高度随机的间隔即使基础间隔为0也能工作
# - 负数会自动转换为正数,不用担心配置错误以及极端边界情况
# 实验建议:试试 proactive_thinking_interval=0 + delta_sigma 非常大 的纯随机模式!
# 结果保证生成的间隔永远为正数负数会取绝对值最小1秒最大24小时
enable_ids = [] # 启用主动思考的范围,不区分群聊和私聊,为空则不限制
# 主动思考prompt模板{time}会被替换为实际的沉默时间(如"2小时30分15秒"
proactive_thinking_prompt_template = """现在当前的聊天里面已经隔了{time}没有人发送消息了,请你结合上下文以及群聊里面之前聊过的话题和你的人设来决定要不要主动发送消息,你可以选择:
1. 继续保持沉默(当{time}以前已经结束了一个话题并且你不想挑起新话题时)
2. 选择回复(当{time}以前你发送了一条消息且没有人回复你时、你想主动挑起一个话题时)
请根据当前情况做出选择。如果选择回复,请直接发送你想说的内容;如果选择保持沉默,请只回复""(注意:这个词不会被发送到群聊中)。"""
# 特定聊天流配置示例:
# [
# ["", "8:00,1", "12:00,1.2", "18:00,1.5", "01:00,0.6"], # 全局默认配置
@@ -170,6 +140,46 @@ proactive_thinking_prompt_template = """现在当前的聊天里面已经隔了{
# - 后续元素是"时间,频率"格式,表示从该时间开始使用该活跃度,直到下一个时间点
# - 优先级:特定聊天流配置 > 全局配置 > 默认 talk_frequency
# 主动思考功能配置仅在focus模式下生效
enable_proactive_thinking = false # 是否启用主动思考功能
proactive_thinking_interval = 1500 # 主动思考触发间隔时间默认1500秒25分钟
# TIPS:
# 创意玩法可以设置为0设置为0时将基于delta_sigma生成纯随机间隔
# 负数保险:如果出现了负数,会自动使用绝对值
proactive_thinking_in_private = true # 主动思考可以在私聊里面启用
proactive_thinking_in_group = true # 主动思考可以在群聊里面启用
# 主动思考启用范围配置 - 按平台和类型分别配置,建议平台配置为小写
# 格式:["platform:user_id", "platform:user_id", ...]
# 示例:["qq:123456789", "telegram:user123", "bilibili:987654321"]
proactive_thinking_enable_in_private = [
] # 启用主动思考的私聊范围,为空则不限制
proactive_thinking_enable_in_groups = [
] # 启用主动思考的群聊范围,为空则不限制
delta_sigma = 120 # 正态分布的标准差,控制时间间隔的随机程度
# 特殊用法:
# - 设置为0禁用正态分布使用固定间隔
# - 设置得很大如6000产生高度随机的间隔即使基础间隔为0也能工作
# - 负数会自动转换为正数,不用担心配置错误以及极端边界情况
# 实验建议:试试 proactive_thinking_interval=0 + delta_sigma 非常大 的纯随机模式!
# 结果保证生成的间隔永远为正数负数会取绝对值最小1秒最大24小时
# 主动思考prompt模板{time}会被替换为实际的沉默时间(如"2小时30分15秒"
proactive_thinking_prompt_template = """现在当前的聊天里面已经隔了{time}没有人发送消息了,请你结合上下文以及群聊里面之前聊过的话题和你的人设来决定要不要主动发送消息,你可以选择:
1. 继续保持沉默(当{time}以前已经结束了一个话题并且你不想挑起新话题时)
2. 选择回复(当{time}以前你发送了一条消息且没有人回复你时、你想主动挑起一个话题时)
请根据当前情况做出选择。如果选择回复,请直接发送你想说的内容;如果选择保持沉默,请只回复""(注意:这个词不会被发送到群聊中)。"""
# 你可以在这里配置主动思考的prompt但是务必不要修改{time}一类的占位符不然会影响主动思考的质量因为time占位符会在实际的prompt里面被替换为时间间隔
# 自己配置的建议是中间的情况描述
[relationship]
enable_relationship = true # 是否启用关系系统