mirror of https://github.com/Mai-with-u/MaiBot.git
feat:可以关闭回复前黑话自动提取
parent
11dd9ece13
commit
216c51d7a2
|
|
@ -188,6 +188,13 @@ class ExpressionLearner:
|
|||
if not context:
|
||||
continue
|
||||
|
||||
# 过滤掉包含 SELF 的内容(不学习)
|
||||
if "SELF" in (situation or "") or "SELF" in (style or "") or "SELF" in context:
|
||||
logger.info(
|
||||
f"跳过包含 SELF 的表达方式: situation={situation}, style={style}, source_id={source_id}"
|
||||
)
|
||||
continue
|
||||
|
||||
filtered_expressions.append((situation, style, context))
|
||||
|
||||
learnt_expressions = filtered_expressions
|
||||
|
|
@ -689,6 +696,11 @@ class ExpressionLearner:
|
|||
if not content:
|
||||
continue
|
||||
|
||||
# 过滤掉包含 SELF 的黑话,不学习
|
||||
if "SELF" in content:
|
||||
logger.info(f"跳过包含 SELF 的黑话: {content}")
|
||||
continue
|
||||
|
||||
# 检查是否包含机器人名称
|
||||
if contains_bot_self_name(content):
|
||||
logger.info(f"跳过包含机器人昵称/别名的黑话: {content}")
|
||||
|
|
|
|||
|
|
@ -488,6 +488,10 @@ class DefaultReplyer:
|
|||
duration = end_time - start_time
|
||||
return name, result, duration
|
||||
|
||||
async def _build_disabled_jargon_explanation(self) -> str:
|
||||
"""当关闭黑话解释时使用的占位协程,避免额外的LLM调用"""
|
||||
return ""
|
||||
|
||||
def build_chat_history_prompts(
|
||||
self, message_list_before_now: List[DatabaseMessages], target_user_id: str, sender: str
|
||||
) -> Tuple[str, str]:
|
||||
|
|
@ -819,7 +823,14 @@ class DefaultReplyer:
|
|||
show_actions=True,
|
||||
)
|
||||
|
||||
# 并行执行八个构建任务(包括黑话解释)
|
||||
# 根据配置决定是否启用黑话解释
|
||||
enable_jargon_explanation = getattr(global_config.expression, "enable_jargon_explanation", True)
|
||||
if enable_jargon_explanation:
|
||||
jargon_coroutine = explain_jargon_in_context(chat_id, message_list_before_short, chat_talking_prompt_short)
|
||||
else:
|
||||
jargon_coroutine = self._build_disabled_jargon_explanation()
|
||||
|
||||
# 并行执行八个构建任务(包括黑话解释,可配置关闭)
|
||||
task_results = await asyncio.gather(
|
||||
self._time_and_run_task(
|
||||
self.build_expression_habits(chat_talking_prompt_short, target, reply_reason, think_level=think_level),
|
||||
|
|
@ -837,10 +848,7 @@ class DefaultReplyer:
|
|||
),
|
||||
"memory_retrieval",
|
||||
),
|
||||
self._time_and_run_task(
|
||||
explain_jargon_in_context(chat_id, message_list_before_short, chat_talking_prompt_short),
|
||||
"jargon_explanation",
|
||||
),
|
||||
self._time_and_run_task(jargon_coroutine, "jargon_explanation"),
|
||||
)
|
||||
|
||||
# 任务名称中英文映射
|
||||
|
|
|
|||
|
|
@ -467,6 +467,10 @@ class PrivateReplyer:
|
|||
duration = end_time - start_time
|
||||
return name, result, duration
|
||||
|
||||
async def _build_disabled_jargon_explanation(self) -> str:
|
||||
"""当关闭黑话解释时使用的占位协程,避免额外的LLM调用"""
|
||||
return ""
|
||||
|
||||
async def build_actions_prompt(
|
||||
self, available_actions: Dict[str, ActionInfo], chosen_actions_info: Optional[List[ActionPlannerInfo]] = None
|
||||
) -> str:
|
||||
|
|
@ -702,7 +706,14 @@ class PrivateReplyer:
|
|||
show_actions=True,
|
||||
)
|
||||
|
||||
# 并行执行九个构建任务(包括黑话解释)
|
||||
# 根据配置决定是否启用黑话解释
|
||||
enable_jargon_explanation = getattr(global_config.expression, "enable_jargon_explanation", True)
|
||||
if enable_jargon_explanation:
|
||||
jargon_coroutine = explain_jargon_in_context(chat_id, message_list_before_short, chat_talking_prompt_short)
|
||||
else:
|
||||
jargon_coroutine = self._build_disabled_jargon_explanation()
|
||||
|
||||
# 并行执行九个构建任务(包括黑话解释,可配置关闭)
|
||||
task_results = await asyncio.gather(
|
||||
self._time_and_run_task(
|
||||
self.build_expression_habits(chat_talking_prompt_short, target, reply_reason), "expression_habits"
|
||||
|
|
@ -720,10 +731,7 @@ class PrivateReplyer:
|
|||
),
|
||||
"memory_retrieval",
|
||||
),
|
||||
self._time_and_run_task(
|
||||
explain_jargon_in_context(chat_id, message_list_before_short, chat_talking_prompt_short),
|
||||
"jargon_explanation",
|
||||
),
|
||||
self._time_and_run_task(jargon_coroutine, "jargon_explanation"),
|
||||
)
|
||||
|
||||
# 任务名称中英文映射
|
||||
|
|
|
|||
|
|
@ -325,6 +325,9 @@ class ExpressionConfig(ConfigBase):
|
|||
all_global_jargon: bool = False
|
||||
"""是否将所有新增的jargon项目默认为全局(is_global=True),chat_id记录第一次存储时的id。注意,此功能关闭后,已经记录的全局黑话不会改变,需要手动删除"""
|
||||
|
||||
enable_jargon_explanation: bool = True
|
||||
"""是否在回复前尝试对上下文中的黑话进行解释(关闭可减少一次LLM调用,仅影响回复前的黑话匹配与解释,不影响黑话学习)"""
|
||||
|
||||
def _parse_stream_config_to_chat_id(self, stream_config_str: str) -> Optional[str]:
|
||||
"""
|
||||
解析流配置字符串并生成对应的 chat_id
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[inner]
|
||||
version = "7.1.8"
|
||||
version = "7.2.0"
|
||||
|
||||
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
||||
# 如果你想要修改配置文件,请递增version的值
|
||||
|
|
@ -93,6 +93,7 @@ reflect_operator_id = "" # 表达反思操作员ID,格式:platform:id:type (
|
|||
allow_reflect = [] # 允许进行表达反思的聊天流ID列表,格式:["qq:123456:private", "qq:654321:group", ...],只有在此列表中的聊天流才会提出问题并跟踪。如果列表为空,则所有聊天流都可以进行表达反思(前提是 reflect = true)
|
||||
|
||||
all_global_jargon = true # 是否开启全局黑话模式,注意,此功能关闭后,已经记录的全局黑话不会改变,需要手动删除
|
||||
enable_jargon_explanation = true # 是否在回复前尝试对上下文中的黑话进行解释(关闭可减少一次LLM调用,仅影响回复前的黑话匹配与解释,不影响黑话学习)
|
||||
|
||||
|
||||
[chat] # 麦麦的聊天设置
|
||||
|
|
|
|||
Loading…
Reference in New Issue