feat: 优化回忆录内容处理和章节分类逻辑

- 更新 get_system_prompt 函数,增强对话内容的核心信息提炼和分类能力,确保只保留与人生经历相关的实质内容。
- 修改 _classify_chapter_category 函数,增加对无实质回忆录价值内容的处理,返回 None 以跳过无效段落。
- 在 Android 客户端中,更新章节阅读视图以移除内嵌章节标题,提升排版一致性。
- 新增 TextUtils 工具函数,专门用于移除 LLM 生成的内嵌章节标题,确保正文内容的流畅性。
This commit is contained in:
penghanyuan
2026-03-02 19:47:32 +01:00
parent 4a331428f7
commit 8b4a058640
5 changed files with 89 additions and 32 deletions

View File

@@ -48,10 +48,11 @@ fun ChapterReadingView(
modifier = Modifier.padding(bottom = 24.dp)
)
// 正文内容(支持 Markdown移除{{IMAGE}}占位符如果没有图片)
val processedContent = TextUtils.removeImagePlaceholders(
chapter.content,
hasImages = chapter.images.isNotEmpty()
val processedContent = TextUtils.removeInlineChapterHeadings(
TextUtils.removeImagePlaceholders(
chapter.content,
hasImages = chapter.images.isNotEmpty()
)
)
MarkdownText(
content = processedContent,

View File

@@ -64,10 +64,11 @@ fun FullTextReadingView(
modifier = Modifier.padding(bottom = 16.dp)
)
// 章节内容(支持 Markdown移除{{IMAGE}}占位符如果没有图片)
val processedContent = TextUtils.removeImagePlaceholders(
chapter.content,
hasImages = chapter.images.isNotEmpty()
val processedContent = TextUtils.removeInlineChapterHeadings(
TextUtils.removeImagePlaceholders(
chapter.content,
hasImages = chapter.images.isNotEmpty()
)
)
MarkdownText(
content = processedContent,

View File

@@ -66,6 +66,24 @@ object TextUtils {
return quotePattern.findAll(text).map { it.groupValues[1] }.toList()
}
/**
* 移除 LLM 生成的内嵌章节标题(如 "章节:信念与价值观"、"## 章节:童年与成长背景"
* 这些标题已由 UI 单独渲染,混在正文中会导致排版突兀
*/
fun removeInlineChapterHeadings(content: String?): String {
if (content.isNullOrBlank()) return ""
return content
// markdown 标题格式: #{1,6} 章节[:]...
.replace(Regex("^#{1,6}\\s*章节[:].*$", RegexOption.MULTILINE), "")
// 粗体格式: **章节:...**
.replace(Regex("\\*\\*章节[:].+?\\*\\*"), "")
// 纯文本格式: 独立一行的 "章节:..."
.replace(Regex("^章节[:].+$", RegexOption.MULTILINE), "")
// 清理移除后产生的多余空行
.replace(Regex("\n{3,}"), "\n\n")
.trim()
}
/**
* 移除图片占位符
* 如果没有图片,移除所有{{{{IMAGE:...}}}}和{{IMAGE:...}}格式的占位符