feat: AI回复格式约束 + 前端清洗器增强

- prompt: 禁止**粗体*斜体等内联标记、HTML标签、表格,标题仅限###
- 前端_cleanAiText: 移除$N占位符、HTML标签、多余#标题降级
- 确认卡片/结构化消息不受影响
This commit is contained in:
MingNian
2026-06-22 14:14:42 +08:00
parent 431b72d49a
commit 6ce010e46a
2 changed files with 20 additions and 4 deletions

View File

@@ -34,6 +34,16 @@ public sealed class PromptManager
-
- 使
- AI
- 使 ******~~线~~ Markdown
- 使 HTML
- 使 Markdown |--|--|
- 使 ### 使 #######
- 使 -
- 120 mmHg6.2 mmol/L
- $
- MedicalBoundaryRules
""";
private const string DefaultPrompt = """

View File

@@ -1243,10 +1243,16 @@ class ChatMessagesView extends ConsumerWidget {
/// 清理 AI 返回文本中的异常占位符Markdown 格式交给 MarkdownBody 渲染)
static String _cleanAiText(String text) {
return text
.replaceAll('\$1', '') // AI 偶尔输出 $1 占位符(正则残留)
.replaceAll(RegExp(r'\n{3,}'), '\n\n')
.trim();
var t = text;
// 移除 $1、$2 等占位符
t = t.replaceAll(RegExp(r'\$\d+'), '');
// 移除残留 HTML 标签
t = t.replaceAll(RegExp(r'<[^>]+>'), '');
// 行首 # 超过 3 个降为 ###
t = t.replaceAllMapped(RegExp(r'^#{4,}\s', multiLine: true), (_) => '### ');
// 压缩多余空行
t = t.replaceAll(RegExp(r'\n{3,}'), '\n\n');
return t.trim();
}
String _freqLabel(String freq) {