Files
ai-companion/app/tests/test_profile_live.py
T
ylhan 20cfaa6ef7 基线:姓名档案修复、疑问句防误写、搜索与传输测试
这是进入 Pipecat Flows 改造前的回滚点。
提交时已核对本地与线上代码 md5 一致(engine.py 7e97bad8、
bot_server.py 1cf543ae),所以这个提交就是当前线上状态。

内容(此前一直在线上运行但未提交的改动):
- 姓名档案:用户自报"我叫林"同步写 confirmed 姓名,重连后恢复
- 疑问句防误写:"谁吗"之类的疑问句不再被覆盖成姓名
- 新增 test_profile_memory.py(姓名档案专项回归)
- 新增 test_profile_live.py(需要真实 LLM 的现场测试)
- 搜索、身份、记忆测试的相应补充

背景:下一步要按 P1-Pipecat Flows Agent化与记忆改造交接.md
渐进引入 Pipecat Flows,交接文档明确要求先保护基线、不得
reset/checkout/覆盖现有改动。此提交即该基线。
2026-09-16 12:48:18 +08:00

63 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""用生产记忆库和真实 LLM 验证当前用户称呼,不加载 STT/TTS。"""
from __future__ import annotations
import asyncio
import sys
from pathlib import Path
import numpy as np
ROOT = Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(ROOT))
from app.config import AppConfig # noqa: E402
from app.engine import ConversationEngine, EventKind # noqa: E402
from app.identity import ManualIdentityProvider # noqa: E402
from app.llm import FallbackProvider, create_provider # noqa: E402
from app.memory import SQLiteMemoryStore # noqa: E402
class SilentTTS:
sample_rate = 16000
def synthesize(self, _text):
return np.zeros(0, dtype=np.float32)
async def main() -> int:
cfg = AppConfig.load()
cfg.search.enabled = False
cfg.memory.auto_extract_enabled = False
memory = SQLiteMemoryStore(cfg.memory.db_path)
await memory.open()
llm = FallbackProvider(
create_provider(cfg.llm), create_provider(cfg.llm_fallback))
engine = ConversationEngine(
cfg, llm, memory, ManualIdentityProvider(), SilentTTS())
try:
await engine.start_session(user_id=cfg.default_user_id)
loaded_name = engine.identity.current().display_name
reply_parts = []
async for event in engine.respond_to_text("我是谁?请只说我的称呼。"):
if event.kind == EventKind.RESPONSE_DELTA:
reply_parts.append(event.text)
reply = "".join(reply_parts).strip()
if loaded_name != "林":
raise AssertionError(f"档案称呼未恢复:{loaded_name!r}")
if "林" not in reply or cfg.default_user_id in reply:
raise AssertionError(f"回答未正确使用称呼:{reply!r}")
print(f"恢复称呼: {loaded_name}")
print(f"真实回答: {reply}")
print("生产记忆 + 真实 LLM 验收:PASS")
return 0
finally:
await engine.end_session()
await memory.close()
await llm.aclose()
if __name__ == "__main__":
raise SystemExit(asyncio.run(main()))