diff --git a/backend/.env.ex b/backend/.env.ex index a27766d..e4d85e4 100644 --- a/backend/.env.ex +++ b/backend/.env.ex @@ -41,6 +41,7 @@ UPLOAD_DIR=uploads COZE_OAUTH_CLIENT_ID=1114009328887 COZE_OAUTH_PUBLIC_KEY_ID=GGs9pw0BDHx2k9vGGehUyRgKV-PyUWLBncDs-YNNN_I COZE_OAUTH_PRIVATE_KEY_PATH=/app/secrets/coze_private_key.pem +COZE_WORKSPACE_ID=7461992708538974244 COZE_PRACTICE_BOT_ID=7602204855037591602 # Dify 工作流 API Key 配置 diff --git a/backend/app/api/v1/practice.py b/backend/app/api/v1/practice.py index aa1e3a9..cb60496 100644 --- a/backend/app/api/v1/practice.py +++ b/backend/app/api/v1/practice.py @@ -734,14 +734,27 @@ async def end_practice_session( except Exception: pass + # 将 ORM 对象转换为响应格式,避免 DetachedInstanceError + session_data = PracticeSessionResponse( + id=session.id, + session_id=session.session_id, + user_id=session.user_id, + scene_id=session.scene_id, + scene_name=session.scene_name or "", + scene_type=session.scene_type, + conversation_id=session.conversation_id, + start_time=session.start_time, + end_time=session.end_time, + duration_seconds=session.duration_seconds or 0, + turns=session.turns or 0, + status=session.status, + created_at=session.created_at + ) + return ResponseModel( code=200, message="会话已结束", - data={ - "session": session, - "exp_result": exp_result, - "new_badges": new_badges - } + data=session_data ) except HTTPException: