Spaces:
Sleeping
Sleeping
File size: 596 Bytes
f9b7370 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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) |