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:
@@ -7,8 +7,7 @@ import pytest
|
||||
|
||||
from app.agents.chat.interview_reply_length import (
|
||||
ReplyLengthMode,
|
||||
bump_reply_length_strategy_for_background_voice,
|
||||
compute_reply_length_strategy,
|
||||
bump_reply_plan_for_background_voice,
|
||||
compute_reply_plan,
|
||||
)
|
||||
from app.agents.state_schema import MemoirStateSchema
|
||||
@@ -29,10 +28,9 @@ def _fake_settings(**overrides: object) -> SimpleNamespace:
|
||||
|
||||
|
||||
def test_strategy_brief_when_very_short() -> None:
|
||||
s = compute_reply_length_strategy(
|
||||
5,
|
||||
likely_new_detail=False,
|
||||
likely_chit_chat=False,
|
||||
s = compute_reply_plan(
|
||||
"x" * 5,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
assert s.mode == ReplyLengthMode.brief
|
||||
@@ -41,10 +39,9 @@ def test_strategy_brief_when_very_short() -> None:
|
||||
|
||||
|
||||
def test_strategy_standard_mid_length() -> None:
|
||||
s = compute_reply_length_strategy(
|
||||
50,
|
||||
likely_new_detail=True,
|
||||
likely_chit_chat=False,
|
||||
s = compute_reply_plan(
|
||||
"x" * 50,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
assert s.mode == ReplyLengthMode.standard
|
||||
@@ -53,10 +50,11 @@ def test_strategy_standard_mid_length() -> None:
|
||||
|
||||
|
||||
def test_strategy_long_chit_stays_standard() -> None:
|
||||
s = compute_reply_length_strategy(
|
||||
120,
|
||||
likely_new_detail=False,
|
||||
likely_chit_chat=True,
|
||||
msg = "今天天气真好哈哈" * 11
|
||||
assert len(msg) >= 80
|
||||
s = compute_reply_plan(
|
||||
msg,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
assert s.mode == ReplyLengthMode.standard
|
||||
@@ -64,10 +62,12 @@ def test_strategy_long_chit_stays_standard() -> None:
|
||||
|
||||
|
||||
def test_strategy_long_with_new_detail_expanded() -> None:
|
||||
s = compute_reply_length_strategy(
|
||||
120,
|
||||
likely_new_detail=True,
|
||||
likely_chit_chat=False,
|
||||
base = "第一次认识他"
|
||||
msg = (base + "x" * 200)[:120]
|
||||
assert len(msg) == 120
|
||||
s = compute_reply_plan(
|
||||
msg,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
assert s.mode == ReplyLengthMode.expanded
|
||||
@@ -76,24 +76,27 @@ def test_strategy_long_with_new_detail_expanded() -> None:
|
||||
|
||||
|
||||
def test_strategy_boundary_len_20_brief_len_21_standard() -> None:
|
||||
a = compute_reply_length_strategy(
|
||||
20, likely_new_detail=False, likely_chit_chat=False, settings=_fake_settings()
|
||||
a = compute_reply_plan(
|
||||
"x" * 20,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
b = compute_reply_length_strategy(
|
||||
21, likely_new_detail=False, likely_chit_chat=False, settings=_fake_settings()
|
||||
b = compute_reply_plan(
|
||||
"x" * 21,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
assert a.mode == ReplyLengthMode.brief
|
||||
assert b.mode == ReplyLengthMode.standard
|
||||
|
||||
|
||||
def test_bump_standard_only_for_cadre_military() -> None:
|
||||
s0 = compute_reply_length_strategy(
|
||||
50,
|
||||
likely_new_detail=False,
|
||||
likely_chit_chat=False,
|
||||
s0 = compute_reply_plan(
|
||||
"x" * 50,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
bumped = bump_reply_length_strategy_for_background_voice(
|
||||
bumped = bump_reply_plan_for_background_voice(
|
||||
s0,
|
||||
background_voice="cadre",
|
||||
settings=_fake_settings(
|
||||
@@ -104,16 +107,15 @@ def test_bump_standard_only_for_cadre_military() -> None:
|
||||
assert bumped.max_tokens == s0.max_tokens + 40
|
||||
assert bumped.max_chars_per_segment == s0.max_chars_per_segment + 40
|
||||
|
||||
brief = compute_reply_length_strategy(
|
||||
5,
|
||||
likely_new_detail=False,
|
||||
likely_chit_chat=False,
|
||||
brief = compute_reply_plan(
|
||||
"x" * 5,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(
|
||||
chat_interview_cadre_military_standard_extra_tokens=40,
|
||||
chat_interview_cadre_military_standard_extra_chars=40,
|
||||
),
|
||||
)
|
||||
same = bump_reply_length_strategy_for_background_voice(
|
||||
same = bump_reply_plan_for_background_voice(
|
||||
brief,
|
||||
background_voice="military",
|
||||
settings=_fake_settings(
|
||||
@@ -149,13 +151,14 @@ def test_plan_long_chit_stays_standard_not_expanded() -> None:
|
||||
|
||||
|
||||
def test_strategy_boundary_len_79_standard_len_80_long_branch() -> None:
|
||||
a = compute_reply_length_strategy(
|
||||
79, likely_new_detail=False, likely_chit_chat=False, settings=_fake_settings()
|
||||
a = compute_reply_plan(
|
||||
"x" * 79,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
b = compute_reply_length_strategy(
|
||||
80,
|
||||
likely_new_detail=False,
|
||||
likely_chit_chat=False,
|
||||
b = compute_reply_plan(
|
||||
"x" * 80,
|
||||
background_voice=None,
|
||||
settings=_fake_settings(),
|
||||
)
|
||||
assert a.mode == ReplyLengthMode.standard
|
||||
|
||||
Reference in New Issue
Block a user