fix: 修复打个招呼的bug

This commit is contained in:
yangshilin
2026-03-13 14:50:04 +08:00
parent 2eb066dbec
commit ab4fb46c0d
4 changed files with 55 additions and 28 deletions

View File

@@ -478,31 +478,32 @@ async def websocket_endpoint(
return
# 首次连接时检查资料完整性,发送资料收集开场白
missing_profile = _get_missing_profile_fields(user)
if missing_profile:
try:
greetings = await manager.conversation_agent.generate_profile_greeting(
conversation_id=conversation_id,
missing_fields=missing_profile,
nickname=user.nickname or "",
)
import asyncio as _asyncio_greet
for i, text in enumerate(greetings):
await manager.send_message(conversation_id, {
"type": MessageType.AGENT_RESPONSE,
"conversation_id": conversation_id,
"data": {"text": text, "index": i, "total": len(greetings)},
"timestamp": datetime.now(timezone.utc).isoformat()
})
if i < len(greetings) - 1:
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:
# 首次连接时检查:若 Redis 已有历史(用户曾进入过此对话),不再发送开场白,避免重复/自问自答
history = await redis_service.get_conversation_history(conversation_id)
if not history:
# 空对话:发送开场白(资料收集或正式访谈)
missing_profile = _get_missing_profile_fields(user)
if missing_profile:
try:
greetings = await manager.conversation_agent.generate_profile_greeting(
conversation_id=conversation_id,
missing_fields=missing_profile,
nickname=user.nickname or "",
)
import asyncio as _asyncio_greet
for i, text in enumerate(greetings):
await manager.send_message(conversation_id, {
"type": MessageType.AGENT_RESPONSE,
"conversation_id": conversation_id,
"data": {"text": text, "index": i, "total": len(greetings)},
"timestamp": datetime.now(timezone.utc).isoformat()
})
if i < len(greetings) - 1:
await _asyncio_greet.sleep(0.5)
except Exception as e:
logger.error(f"发送资料收集开场白失败: {e}", exc_info=True)
else:
# 资料已完整AI 先开口提问
try:
state = await get_or_create_state(user_id, db)
user_profile_context = format_user_profile_context(