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

@@ -98,16 +98,20 @@ def _detect_stage(user_message: str, fallback_stage: str) -> str:
return fallback_stage
def _classify_chapter_category(text: str, fallback_stage: str, llm=None) -> str:
def _classify_chapter_category(text: str, fallback_stage: str, llm=None) -> str | None:
"""
将内容分类到 8 个章节类别之一。
优先使用 LLM失败则按 5-stage 关键词映射到默认类别。
如果 LLM 判定内容无实质回忆录价值,返回 None。
"""
if llm:
try:
prompt = get_chapter_classification_prompt(text)
response = llm.invoke(prompt)
category = response.content.strip().lower()
if category == "none":
logger.info(f"LLM 判定内容无回忆录价值,跳过: {text[:80]}...")
return None
if category in CHAPTER_CATEGORIES:
return category
except Exception as e:
@@ -264,6 +268,9 @@ def process_memoir_segments(self, user_id: str, segment_ids: List[str]):
# 8-category 章节分类
chapter_category = _classify_chapter_category(text, detected_stage, llm)
if chapter_category is None:
logger.info(f"段落无回忆录价值,跳过: segment_id={segment.id}")
continue
category_to_segments.setdefault(chapter_category, []).append(segment)
# 按 8 分类生成章节内容