feat 为focus加入 mentioned bonus

This commit is contained in:
SengokuCola
2025-07-24 22:03:27 +08:00
parent 28861d60b1
commit 33606e7028
6 changed files with 33 additions and 15 deletions

View File

@@ -279,9 +279,15 @@ class ActionPlanner:
self.last_obs_time_mark = time.time() self.last_obs_time_mark = time.time()
if mode == ChatMode.FOCUS: if mode == ChatMode.FOCUS:
if global_config.normal_chat.mentioned_bot_inevitable_reply:
mentioned_bonus = "有人提到你"
if global_config.normal_chat.at_bot_inevitable_reply:
mentioned_bonus = "有人提到你或者at你"
by_what = "聊天内容" by_what = "聊天内容"
target_prompt = '\n "target_message_id":"触发action的消息id"' target_prompt = '\n "target_message_id":"触发action的消息id"'
no_action_block = """重要说明1 no_action_block = f"""重要说明1
- 'no_reply' 表示只进行不进行回复,等待合适的回复时机 - 'no_reply' 表示只进行不进行回复,等待合适的回复时机
- 当你刚刚发送了消息没有人回复时选择no_reply - 当你刚刚发送了消息没有人回复时选择no_reply
- 当你一次发送了太多消息为了避免打扰聊天节奏选择no_reply - 当你一次发送了太多消息为了避免打扰聊天节奏选择no_reply
@@ -289,13 +295,13 @@ class ActionPlanner:
动作reply 动作reply
动作描述:参与聊天回复,发送文本进行表达 动作描述:参与聊天回复,发送文本进行表达
- 你想要闲聊或者随便附和 - 你想要闲聊或者随便附和
- 有人提到你 - {mentioned_bonus}
- 如果你刚刚进行了回复,不要对同一个话题重复回应 - 如果你刚刚进行了回复,不要对同一个话题重复回应
{ {{
"action": "reply", "action": "reply",
"target_message_id":"触发action的消息id", "target_message_id":"触发action的消息id",
"reason":"回复的原因" "reason":"回复的原因"
} }}
""" """
else: else:

View File

@@ -450,6 +450,9 @@ class DefaultReplyer:
def _parse_reply_target(self, target_message: str) -> tuple: def _parse_reply_target(self, target_message: str) -> tuple:
sender = "" sender = ""
target = "" target = ""
# 添加None检查防止NoneType错误
if target_message is None:
return sender, target
if ":" in target_message or "" in target_message: if ":" in target_message or "" in target_message:
# 使用正则表达式匹配中文或英文冒号 # 使用正则表达式匹配中文或英文冒号
parts = re.split(pattern=r"[:]", string=target_message, maxsplit=1) parts = re.split(pattern=r"[:]", string=target_message, maxsplit=1)
@@ -462,6 +465,10 @@ class DefaultReplyer:
# 关键词检测与反应 # 关键词检测与反应
keywords_reaction_prompt = "" keywords_reaction_prompt = ""
try: try:
# 添加None检查防止NoneType错误
if target is None:
return keywords_reaction_prompt
# 处理关键词规则 # 处理关键词规则
for rule in global_config.keyword_reaction.keyword_rules: for rule in global_config.keyword_reaction.keyword_rules:
if any(keyword in target for keyword in rule.keywords): if any(keyword in target for keyword in rule.keywords):
@@ -524,7 +531,7 @@ class DefaultReplyer:
# 其他用户的对话 # 其他用户的对话
background_dialogue_list.append(msg_dict) background_dialogue_list.append(msg_dict)
except Exception as e: except Exception as e:
logger.error(f"无法处理历史消息记录: {msg_dict}, 错误: {e}") logger.error(f"![1753364551656](image/default_generator/1753364551656.png)记录: {msg_dict}, 错误: {e}")
# 构建背景对话 prompt # 构建背景对话 prompt
background_dialogue_prompt = "" background_dialogue_prompt = ""

View File

@@ -49,7 +49,7 @@ TEMPLATE_DIR = os.path.join(PROJECT_ROOT, "template")
# 考虑到实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码 # 考虑到实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码
# 对该字段的更新请严格参照语义化版本规范https://semver.org/lang/zh-CN/ # 对该字段的更新请严格参照语义化版本规范https://semver.org/lang/zh-CN/
MMC_VERSION = "0.9.0" MMC_VERSION = "0.9.1-snapshot.1"
def get_key_comment(toml_table, key): def get_key_comment(toml_table, key):

View File

@@ -84,6 +84,12 @@ class ChatConfig(ConfigBase):
use_s4u_prompt_mode: bool = False use_s4u_prompt_mode: bool = False
"""是否使用 s4u 对话构建模式,该模式会分开处理当前对话对象和其他所有对话的内容进行 prompt 构建""" """是否使用 s4u 对话构建模式,该模式会分开处理当前对话对象和其他所有对话的内容进行 prompt 构建"""
mentioned_bot_inevitable_reply: bool = False
"""提及 bot 必然回复"""
at_bot_inevitable_reply: bool = False
"""@bot 必然回复"""
# 修改:基于时段的回复频率配置,改为数组格式 # 修改:基于时段的回复频率配置,改为数组格式
time_based_talk_frequency: list[str] = field(default_factory=lambda: []) time_based_talk_frequency: list[str] = field(default_factory=lambda: [])
""" """
@@ -270,11 +276,7 @@ class NormalChatConfig(ConfigBase):
response_interested_rate_amplifier: float = 1.0 response_interested_rate_amplifier: float = 1.0
"""回复兴趣度放大系数""" """回复兴趣度放大系数"""
mentioned_bot_inevitable_reply: bool = False
"""提及 bot 必然回复"""
at_bot_inevitable_reply: bool = False
"""@bot 必然回复"""
@dataclass @dataclass

View File

@@ -32,13 +32,13 @@ class ReplyAction(BaseAction):
# 动作基本信息 # 动作基本信息
action_name = "reply" action_name = "reply"
action_description = "参与聊天回复,发送文本进行表达" action_description = ""
# 动作参数定义 # 动作参数定义
action_parameters = {} action_parameters = {}
# 动作使用场景 # 动作使用场景
action_require = ["你想要闲聊或者随便附和", "有人提到你", "如果你刚刚进行了回复,不要对同一个话题重复回应"] action_require = [""]
# 关联类型 # 关联类型
associated_types = ["text"] associated_types = ["text"]
@@ -46,6 +46,9 @@ class ReplyAction(BaseAction):
def _parse_reply_target(self, target_message: str) -> tuple: def _parse_reply_target(self, target_message: str) -> tuple:
sender = "" sender = ""
target = "" target = ""
# 添加None检查防止NoneType错误
if target_message is None:
return sender, target
if ":" in target_message or "" in target_message: if ":" in target_message or "" in target_message:
# 使用正则表达式匹配中文或英文冒号 # 使用正则表达式匹配中文或英文冒号
parts = re.split(pattern=r"[:]", string=target_message, maxsplit=1) parts = re.split(pattern=r"[:]", string=target_message, maxsplit=1)

View File

@@ -59,6 +59,9 @@ max_context_size = 25 # 上下文长度
thinking_timeout = 20 # 麦麦一次回复最长思考规划时间超过这个时间的思考会放弃往往是api反应太慢 thinking_timeout = 20 # 麦麦一次回复最长思考规划时间超过这个时间的思考会放弃往往是api反应太慢
replyer_random_probability = 0.5 # 首要replyer模型被选择的概率 replyer_random_probability = 0.5 # 首要replyer模型被选择的概率
mentioned_bot_inevitable_reply = true # 提及 bot 大概率回复
at_bot_inevitable_reply = true # @bot 或 提及bot 大概率回复
use_s4u_prompt_mode = true # 是否使用 s4u 对话构建模式,该模式会更好的把握当前对话对象的对话内容,但是对群聊整理理解能力较差(测试功能!!可能有未知问题!!) use_s4u_prompt_mode = true # 是否使用 s4u 对话构建模式,该模式会更好的把握当前对话对象的对话内容,但是对群聊整理理解能力较差(测试功能!!可能有未知问题!!)
@@ -101,11 +104,8 @@ ban_msgs_regex = [
] ]
[normal_chat] #普通聊天 [normal_chat] #普通聊天
#一般回复参数
willing_mode = "classical" # 回复意愿模式 —— 经典模式classicalmxp模式mxp自定义模式custom需要你自己实现 willing_mode = "classical" # 回复意愿模式 —— 经典模式classicalmxp模式mxp自定义模式custom需要你自己实现
response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数 response_interested_rate_amplifier = 1 # 麦麦回复兴趣度放大系数
mentioned_bot_inevitable_reply = true # 提及 bot 必然回复
at_bot_inevitable_reply = true # @bot 必然回复(包含提及)
[tool] [tool]
enable_in_normal_chat = false # 是否在普通聊天中启用工具 enable_in_normal_chat = false # 是否在普通聊天中启用工具