virgil-ai/src/api/v1/router.py
2025-08-12 21:36:46 +03:00

56 lines
No EOL
1.8 KiB
Python

from fastapi import APIRouter, HTTPException
from src.services.estimation_service_v2 import EstimationService
from . import models
from ...services.chat_service import chat_service
router = APIRouter()
@router.post("/insurance_chat", response_model=models.InsuranceChatResponse)
async def insurance_chat(request: models.InsuranceChatRequest):
"""Handle insurance chat requests"""
try:
result = await chat_service.process_insurance_chat(
message=request.message,
session_id=request.session_id
)
return models.InsuranceChatResponse(
session_id=result["session_id"],
answer=result["answer"],
sources=result["sources"],
history=result["history"],
hooks=result["hooks"],
)
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)
async def estimate(request: models.EstimationRequest):
"""Handle insurance estimation requests"""
try:
if not request.applicants or not request.plans:
raise HTTPException(
status_code=400,
detail="Missing required applicants or plans"
)
estimation_service = EstimationService()
estimation_response = await estimation_service.estimate_insurance(request.applicants, request.phq, request.plans)
return estimation_response
except HTTPException as e:
print("HTTPException in estimate: ", e)
raise e
except Exception as e:
print("Exception in estimate: ", e)
raise HTTPException(
status_code=500,
detail=f"Server error: {str(e)}"
)