Files
life-echo/api/tests/test_interview_prompts.py
Kevin 69a673e6c6 feat(api): 访谈人格/回复长度策略、口述归一、背景语气与输入净稿全链路
Chat 访谈
- 新增 persona 系统(default / warm_listener / curious_guide)与 background_voice 语气层
- 回复长度由 compute_reply_plan 统一决策(brief / standard / expanded),融合信息密度启发式
- 输入净稿(input_normalize):编排层可选 rules/llm 归一用户口语后再喂模型与记忆检索
- 记忆证据注入:按用户话检索 memory evidence 并注入 prompt

Memoir 回忆录
- 口述归一(oral_normalize):segment 原文保留,story 管线取派生净稿作叙事输入
- segment 入队批次门闸:累计字数 + 最长等待秒数,减少零碎提交
- fidelity_check / prompts / narrative_agent 微调
- Alembic 0005:清理跨章节 story 外键

Infra
- Dockerfile 加入 ffmpeg
- pyproject.toml 新增依赖并同步 uv.lock
- .env.example / .env.production 补全新配置项

Tests
- 新增 test_background_voice、test_chat_input_normalize、test_experience_regressions
- 扩展 test_interview_prompts、test_interview_reply_length、test_story_route_oral_invariant

Made-with: Cursor
2026-03-31 23:55:26 +08:00

165 lines
5.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""访谈提示词追问触发与性格Persona拼接回归。"""
from app.agents.chat.personas import normalize_interview_persona
from app.agents.chat.prompts_conversation import (
get_guided_conversation_prompt,
get_opening_prompt,
)
def test_guided_prompt_contains_mandatory_followup_when_heuristic_matches():
p = get_guided_conversation_prompt(
current_stage="childhood",
empty_slots=["place", "people"],
filled_slots={},
user_message="厉害吧 那个女生叫娟娟",
conversation_turn=1,
same_topic_turns=1,
all_stages_coverage=None,
detected_user_stage="childhood",
user_profile_context="",
persona="default",
)
assert "什么时候追问" in p
assert "本轮判定" in p
def test_guided_prompt_persona_curious_guide():
p = get_guided_conversation_prompt(
current_stage="education",
empty_slots=["school"],
filled_slots={},
user_message="还行吧",
conversation_turn=0,
same_topic_turns=0,
all_stages_coverage=None,
detected_user_stage="education",
user_profile_context="",
persona="curious_guide",
)
assert "好奇引导" in p
def test_normalize_interview_persona_unknown_falls_back():
assert normalize_interview_persona("not_a_real_persona") == "default"
assert normalize_interview_persona("") == "default"
def test_guided_prompt_contains_memoir_orientation():
p = get_guided_conversation_prompt(
current_stage="childhood",
empty_slots=["place"],
filled_slots={},
user_message="后来我就去上班了",
conversation_turn=0,
same_topic_turns=0,
all_stages_coverage=None,
detected_user_stage="childhood",
user_profile_context="",
persona="default",
)
assert "对话方向" in p
assert "人生故事" in p
def test_guided_prompt_contains_memory_section_when_evidence():
p = get_guided_conversation_prompt(
current_stage="childhood",
empty_slots=["place"],
filled_slots={},
user_message="后来我就去上班了",
conversation_turn=0,
same_topic_turns=0,
all_stages_coverage=None,
detected_user_stage="childhood",
user_profile_context="",
persona="default",
memory_evidence_text="[摘要:rolling] 1990年生于上海。",
)
assert "相关记忆摘录" in p
assert "过往口述" in p
assert "1990年生于上海" in p
def test_guided_prompt_chit_chat_hint():
p = get_guided_conversation_prompt(
current_stage="childhood",
empty_slots=["place"],
filled_slots={},
user_message="今天天气真好哈哈",
conversation_turn=0,
same_topic_turns=0,
all_stages_coverage=None,
detected_user_stage="childhood",
user_profile_context="",
persona="default",
)
assert "偏闲聊" in p
def test_guided_prompt_reply_length_section_explicit_expanded():
p = get_guided_conversation_prompt(
current_stage="childhood",
empty_slots=["place"],
filled_slots={},
user_message="还行吧",
conversation_turn=0,
same_topic_turns=0,
all_stages_coverage=None,
detected_user_stage="childhood",
user_profile_context="",
persona="default",
reply_length_mode="expanded",
)
assert "本轮回复长度" in p
assert "当前档位expanded" in p
assert "expanded" in p
def test_guided_prompt_reply_length_explicit_brief():
"""档位由 Agent 的 ReplyPlan 传入prompt 不再自行推导。"""
p = get_guided_conversation_prompt(
current_stage="childhood",
empty_slots=["place"],
filled_slots={},
user_message="",
conversation_turn=0,
same_topic_turns=0,
all_stages_coverage=None,
detected_user_stage="childhood",
user_profile_context="",
persona="default",
reply_length_mode="brief",
)
assert "当前档位brief" in p
def test_guided_prompt_background_voice_military() -> None:
p = get_guided_conversation_prompt(
current_stage="childhood",
empty_slots=["place"],
filled_slots={},
user_message="后来我就去上班了",
conversation_turn=0,
same_topic_turns=0,
all_stages_coverage=None,
detected_user_stage="childhood",
user_profile_context="",
persona="default",
background_voice="military",
)
assert "背景语气:军队语境" in p
assert "真诚承接" in p
def test_opening_prompt_military_has_examples_note() -> None:
p = get_opening_prompt(
current_stage="childhood",
empty_slots_readable=["成长的地方"],
user_profile_context="",
persona="default",
background_voice="military",
)
assert "军队语境" in p
assert "(军队语境:简洁" in p or "军队语境" in p