feat(api): 访谈路径轻量门控、Memoir Phase1 批处理与叙事/记忆管线加固
- 新增 utterance_substance:短时/应答/元话语可跳过记忆检索、阶段 LLM 与资料抽取 LLM;可配置 - 输入归一化:LLM 模式默认仅语音/ASR;配置项写入 .env.example - Memoir Phase1:可选 batch LLM 一次性抽取+分类(失败回退逐段);Extraction 空槽位时阶段与 current_stage 对齐,prompt 约束收紧 - 叙事与忠实度:narrative_safety、证据重叠/场合锚点、标题 slots 与履历短语 grounded;fidelity 解析失败 fail-open 可配置 - 章节管线:锁 TTL 上调、锁竞争 Celery 重试、Phase2 immediate singleflight 等;story_pipeline_sync / chapter_compose / memoir_tasks 联动 - Memory:compaction / repo / summarizer / evidence 小修;事实 FTS 未命中是否回退最近事实可配置 - 新增 memoir_pipeline_trace;补充 memoir_reliability 文档与多项回归/门控测试
This commit is contained in:
76
api/tests/test_fidelity_gate.py
Normal file
76
api/tests/test_fidelity_gate.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""FidelityCheckAgent:解析/LLM 失败时的 fail-closed(新建叙事)vs fail-open(续写)。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.agents.memoir.fidelity_check_agent import FidelityCheckAgent
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
def test_fidelity_fail_closed_on_parse_when_not_append(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(settings, "memoir_fidelity_check_enabled", True)
|
||||
monkeypatch.setattr(settings, "memoir_fidelity_fail_open_on_parse_error", False)
|
||||
agent = FidelityCheckAgent()
|
||||
llm = MagicMock()
|
||||
with patch(
|
||||
"app.agents.memoir.fidelity_check_agent.invoke_json_object",
|
||||
side_effect=ValueError("simulated_bad_response"),
|
||||
):
|
||||
assert (
|
||||
agent.passes(
|
||||
oral_text=" oral ",
|
||||
narrative_json='{"paragraphs":[{"content":"x"}]}',
|
||||
llm=llm,
|
||||
is_append=False,
|
||||
)
|
||||
is False
|
||||
)
|
||||
|
||||
|
||||
def test_fidelity_fail_open_on_parse_when_append(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(settings, "memoir_fidelity_check_enabled", True)
|
||||
monkeypatch.setattr(settings, "memoir_fidelity_fail_open_on_parse_error", False)
|
||||
agent = FidelityCheckAgent()
|
||||
llm = MagicMock()
|
||||
with patch(
|
||||
"app.agents.memoir.fidelity_check_agent.invoke_json_object",
|
||||
side_effect=ValueError("simulated_bad_response"),
|
||||
):
|
||||
assert (
|
||||
agent.passes(
|
||||
oral_text=" oral ",
|
||||
narrative_json='{"paragraphs":[{"content":"x"}]}',
|
||||
llm=llm,
|
||||
is_append=True,
|
||||
)
|
||||
is True
|
||||
)
|
||||
|
||||
|
||||
def test_fidelity_fail_open_global_flag_overrides_append(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(settings, "memoir_fidelity_check_enabled", True)
|
||||
monkeypatch.setattr(settings, "memoir_fidelity_fail_open_on_parse_error", True)
|
||||
agent = FidelityCheckAgent()
|
||||
llm = MagicMock()
|
||||
with patch(
|
||||
"app.agents.memoir.fidelity_check_agent.invoke_json_object",
|
||||
side_effect=ValueError("simulated_bad_response"),
|
||||
):
|
||||
assert (
|
||||
agent.passes(
|
||||
oral_text=" oral ",
|
||||
narrative_json='{"paragraphs":[{"content":"x"}]}',
|
||||
llm=llm,
|
||||
is_append=False,
|
||||
)
|
||||
is True
|
||||
)
|
||||
Reference in New Issue
Block a user