正则相关

This commit is contained in:
2026-05-06 00:40:18 +08:00
parent f843a74715
commit 9faccc2c03
32 changed files with 4814 additions and 346 deletions

View File

@@ -201,7 +201,9 @@ class RegexService:
placement: int,
character_name: Optional[str] = None,
preset_name: Optional[str] = None,
message_depth: int = 0
message_depth: int = 0,
is_for_llm: bool = False, # ✅ 新增是否发送给LLM
is_markdown_rendered: bool = False # ✅ 新增是否已Markdown渲染
) -> str:
"""
根据 placement 应用正则规则
@@ -212,6 +214,8 @@ class RegexService:
character_name: 当前角色卡名称
preset_name: 当前预设名称
message_depth: 消息深度
is_for_llm: 是否用于发送给 LLM影响 promptOnly 逻辑)
is_markdown_rendered: 是否是 Markdown 渲染后的内容(影响 markdownOnly 逻辑)
Returns:
处理后的文本
@@ -220,6 +224,14 @@ class RegexService:
result = text
for rule in rules:
# ✅ 检查 promptOnly如果规则只应用于LLM但当前不是LLM场景则跳过
if rule.promptOnly and not is_for_llm:
continue
# ✅ 检查 markdownOnly如果规则只应用于Markdown渲染但当前不是渲染后则跳过
if rule.markdownOnly and not is_markdown_rendered:
continue
# 检查此规则是否适用于当前 placement
if placement not in [p.value for p in rule.placement]:
continue