diff --git a/src/api/v1/router.py b/src/api/v1/router.py index 726ff81..0e37edf 100644 --- a/src/api/v1/router.py +++ b/src/api/v1/router.py @@ -25,6 +25,7 @@ async def insurance_chat(request: models.InsuranceChatRequest): ) except Exception as e: + # raise e raise HTTPException(status_code=500, detail=f"Error processing chat request: {str(e)}") @router.post("/estimation", response_model=models.EstimationResponse) diff --git a/src/models.py b/src/models.py index f4f641b..b0af4d4 100644 --- a/src/models.py +++ b/src/models.py @@ -111,7 +111,9 @@ class ChatHook(BaseModel): class AIChatResponse(BaseModel): answer: str - hooks: List[ChatHook] = [] + show_plans: list[int] | None = None + compare_plans: list[int] | None = None + update_applicants: list[Applicant] | None = None class InsuranceChatResponse(BaseModel): session_id: str diff --git a/src/services/chat_service.py b/src/services/chat_service.py index 335e58c..c45babb 100644 --- a/src/services/chat_service.py +++ b/src/services/chat_service.py @@ -1,6 +1,8 @@ import json import httpx from typing import Dict, Any, List, Optional + +from src.models import ApplicantParam, ChatHook, PlansParam from ..config import settings from .session_service import session_service from ..api.v1.models import Source, HistoryItem @@ -115,7 +117,25 @@ class ChatService: ai_response = json.loads(chat_response.get("message", {})) ai_message = ai_response.get("message", "") - hooks = ai_response.get("hooks", []) + compare_plans = ai_response.get("compare_plans") + show_plans = ai_response.get("show_plans") + update_applicants = ai_response.get("update_applicants") + hooks = [] + if update_applicants: + hooks.append(ChatHook( + tool="update_applicants", + params=ApplicantParam(applicants=update_applicants) + )) + elif compare_plans: + hooks.append(ChatHook( + tool="compare_plans", + params=PlansParam(plans=compare_plans) + )) + elif show_plans: + hooks.append(ChatHook( + tool="show_plans", + params=PlansParam(plans=show_plans) + )) return { "session_id": session_id, @@ -131,7 +151,8 @@ class ChatService: "session_id": session_id or "fallback-session", "answer": f"I'm sorry, I'm experiencing technical difficulties. Please try again later. Error: {str(e)}", "sources": [], - "history": [] + "history": [], + "hooks": [], } # Global chat service instance