feat(api): 叙事 prompt、职业上下文、读路径章节、WS 解耦与错误脱敏

- 回忆录:事实边界补充允许清单;传记文体示例与 JSON 叙事要求对齐
- default 职业提示 occupation_context;cadre/military 退休语境
- GET 章节读路径零写入,prepare_chapter_read_view + markdown_for_response
- 文本归一抽到 core/text_normalize;移除弃用 reply 策略与 recompose_chapters_for_story
- ConversationService:WS 连接/用户段落/结束对话;对外错误固定文案
- 测试:HTTP 脱敏契约、章节读视图、occupation 与 background_voice
This commit is contained in:
Kevin
2026-04-01 11:49:33 +08:00
parent a5473e8fe2
commit 53d9e003af
28 changed files with 598 additions and 397 deletions

View File

@@ -0,0 +1,35 @@
"""default 路径下根据用户职业自由文本注入轻量提示(与 cadre/military 专属块正交)。"""
from __future__ import annotations
from app.agents.chat.background_voice import normalize_background_voice
def get_occupation_chat_hint(occupation: str | None, background_voice: str) -> str:
"""default 路径的通用职业上下文cadre/military 已有专属块,返回空串。"""
if normalize_background_voice(background_voice) != "default":
return ""
occ = (occupation or "").strip()
if not occ:
return ""
return (
f"## 用户职业背景\n"
f"用户从事过「{occ}」相关工作。聊天时自然贴合这一背景,"
f"在用语和追问方向上适度靠近用户的职业经历与知识面,但不要刻意。"
)
def get_occupation_narrative_hint(occupation: str | None, background_voice: str) -> str:
"""default 路径的叙事职业上下文。"""
if normalize_background_voice(background_voice) != "default":
return ""
occ = (occupation or "").strip()
if not occ:
return ""
return (
f"## 用户职业背景(仅供文体微调,须遵守事实边界)\n"
f"用户从事过「{occ}」相关工作。叙事时可适度使用该领域常见的书面用语,"
f"让正文贴近讲述者的身份感。\n"
f"**禁止**因职业背景而补充口述未出现的岗位职责、行业流程、单位层级或专业术语细节;"
f"只有当用户口述里已出现相关表达时,才可顺势书面化。"
)