from fastapi import FastAPI from fastapi.responses import HTMLResponse from pydantic import BaseModel, Field from contextlib import asynccontextmanager from typing import List, Optional from app.database import db_manager from app.agent import shl_agent # 1. Define Schemas inside main.py to ensure compliance class Recommendation(BaseModel): name: str url: str test_type: str class ChatMessage(BaseModel): role: str content: str class ChatRequest(BaseModel): # CRITICAL: The grader expects 'messages', not 'conversation' messages: List[ChatMessage] class ChatResponse(BaseModel): reply: str recommendations: List[Recommendation] = Field(default_factory=list) end_of_conversation: bool = False # 2. Lifecycle @asynccontextmanager async def lifespan(app: FastAPI): catalog_file_path = "shl_product_catalog.json" db_manager.initialize_catalog(catalog_file_path) yield app = FastAPI(lifespan=lifespan) # 3. Frontend UI html_content = """