Spaces:
Sleeping
Sleeping
| 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 | |
| async def root(): | |
| return {"message": "GEN_AI Backend is running ๐"} | |
| 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) |