feat(memoir): 回忆录分段两阶段管线(Phase1 分类 / Phase2 叙事)与配置、测试

This commit is contained in:
Kevin
2026-04-02 16:37:14 +08:00
parent 3ae39838c0
commit 6b930808a3
27 changed files with 1550 additions and 430 deletions

View File

@@ -12,6 +12,7 @@ from fastapi import WebSocket, WebSocketDisconnect, status
from starlette.websockets import WebSocketState
from app.agents.chat.background_voice import infer_background_voice
from app.agents.stage_constants import STAGE_TO_ORDER
from app.agents.chat.prompts_profile import format_user_profile_context
from app.core.db import AsyncSessionLocal
from app.core.dependencies import get_asr_provider
@@ -140,6 +141,19 @@ async def websocket_endpoint(
)
return
# 冷启动对齐 conversation_stage 与 MemoirState.current_stage
# 若对话行已有更靠前的人生阶段STAGE_TO_ORDER 更大),不覆盖以免回退。
memoir_state = await get_or_create_state(user_id, db)
ms = (memoir_state.current_stage or "").strip()
cs = (conversation.conversation_stage or "").strip()
if ms:
if not cs:
conversation.conversation_stage = ms
elif STAGE_TO_ORDER.get(ms, -1) >= STAGE_TO_ORDER.get(cs, -1):
conversation.conversation_stage = ms
await db.commit()
await db.refresh(conversation)
history = await conversation_service.ensure_redis_history_from_db(
conversation_id
)
@@ -180,7 +194,7 @@ async def websocket_endpoint(
logger.error(f"发送资料收集开场白失败: {e}", exc_info=True)
else:
try:
state = await get_or_create_state(user_id, db)
state = memoir_state
user_profile_context = format_user_profile_context(
birth_year=user.birth_year,
birth_place=user.birth_place,