Merge remote-tracking branch 'origin/development' into development

This commit is contained in:
Kevin
2026-03-11 15:21:08 +08:00
9 changed files with 309 additions and 59 deletions

View File

@@ -22,7 +22,8 @@ from database.models import Conversation, Segment
from database.models import User as UserModel
from services.auth_service import verify_token
from services.memoir_state_service import get_or_create_state
from services import asr_service
from services import asr_service, redis_service
from agents.prompts.profile_prompts import format_user_profile_context
logger = logging.getLogger(__name__)
LEGACY_VOICE_SESSION_ID = "legacy"
@@ -498,6 +499,35 @@ async def websocket_endpoint(
await _asyncio_greet.sleep(0.5)
except Exception as e:
logger.error(f"发送资料收集开场白失败: {e}", exc_info=True)
else:
# 资料已完整若为空对话用户通过「打个招呼」进入AI 先开口提问
history = await redis_service.get_conversation_history(conversation_id)
if not history:
try:
state = await get_or_create_state(user_id, db)
user_profile_context = format_user_profile_context(
birth_year=user.birth_year,
birth_place=user.birth_place,
grew_up_place=user.grew_up_place,
occupation=user.occupation,
)
opening_messages = await manager.conversation_agent.generate_opening_message(
conversation_id=conversation_id,
memoir_state=state,
user_profile_context=user_profile_context,
)
import asyncio as _asyncio_open
for i, text in enumerate(opening_messages):
await manager.send_message(conversation_id, {
"type": MessageType.AGENT_RESPONSE,
"conversation_id": conversation_id,
"data": {"text": text, "index": i, "total": len(opening_messages)},
"timestamp": datetime.now(timezone.utc).isoformat()
})
if i < len(opening_messages) - 1:
await _asyncio_open.sleep(0.5)
except Exception as e:
logger.error(f"发送空对话开场白失败: {e}", exc_info=True)
# 主循环:处理消息
while True:
@@ -889,7 +919,9 @@ async def process_user_message(
missing = _get_missing_profile_fields(user)
if missing:
try:
extracted = await agent.extract_profile_from_message(user_message, missing)
extracted = await agent.extract_profile_from_message(
user_message, missing, conversation_id=conversation_id
)
if extracted:
await _apply_extracted_profile(user, extracted, db)