from fastapi import FastAPI, HTTPException from pydantic import BaseModel from .llm import chatgpt app = FastAPI() class ChatRequest(BaseModel): input: str class ChatResponse(BaseModel): response: str @app.get("/") async def root(): return {"message": "GEN_AI Backend is running 🚀"} @app.post("/chat", response_model=ChatResponse) async def chat_endpoint(payload: ChatRequest): text = payload.input.strip() if not text: raise HTTPException(status_code=400, detail="Input cannot be empty") reply = chatgpt(text) return ChatResponse(response=reply)