feat(memoir): 回忆录分段两阶段管线(Phase1 分类 / Phase2 叙事)与配置、测试
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Conversation service — 对话编排(列表、创建、结束、删除、消息、整理)。"""
|
||||
|
||||
import asyncio
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
@@ -23,7 +24,10 @@ from app.features.conversation.tts_delivery import apply_presigned_tts_urls_to_m
|
||||
from app.features.memory import repo as memory_repo
|
||||
from app.features.quota.service import QuotaService
|
||||
from app.ports.storage import ObjectStorage
|
||||
from app.tasks.memoir_tasks import process_memoir_segments
|
||||
from app.tasks.memoir_tasks import (
|
||||
dispatch_pending_memoir_phase2_for_user,
|
||||
process_memoir_phase1,
|
||||
)
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -318,23 +322,26 @@ class ConversationService:
|
||||
self, conversation_id: str, user_id: str, subscription_type: str
|
||||
) -> dict:
|
||||
conv = await self.get_or_404(conversation_id, user_id)
|
||||
segments = await repo.get_segments_for_organize(conversation_id, self._db)
|
||||
if not segments:
|
||||
pending_p1 = await repo.get_segments_pending_phase1(conversation_id, self._db)
|
||||
has_p2 = await repo.conversation_has_pending_phase2(conversation_id, self._db)
|
||||
if not pending_p1 and not has_p2:
|
||||
raise HTTPException(status_code=400, detail="该对话没有可整理的内容")
|
||||
can_submit, quota_message = await self._quota.check_can_submit_organize(
|
||||
user_id, subscription_type
|
||||
)
|
||||
if not can_submit:
|
||||
raise HTTPException(status_code=403, detail=quota_message)
|
||||
segment_ids = [s.id for s in segments]
|
||||
process_memoir_segments.delay(conv.user_id, segment_ids)
|
||||
logger.info(
|
||||
"手动触发对话整理: conversation_id={}, segments={}",
|
||||
conversation_id,
|
||||
len(segment_ids),
|
||||
)
|
||||
if pending_p1:
|
||||
segment_ids = [s.id for s in pending_p1]
|
||||
process_memoir_phase1.delay(conv.user_id, segment_ids)
|
||||
logger.info(
|
||||
"手动触发 Phase1: conversation_id={}, segments={}",
|
||||
conversation_id,
|
||||
len(segment_ids),
|
||||
)
|
||||
await asyncio.to_thread(dispatch_pending_memoir_phase2_for_user, conv.user_id)
|
||||
return {
|
||||
"message": "对话整理任务已提交",
|
||||
"conversation_id": conversation_id,
|
||||
"segments_count": len(segment_ids),
|
||||
"segments_count": len(pending_p1),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user