Gen_AI_Test / backend /main.py
AyushMatchbest
initial
f9b7370
Raw
History Blame Contribute Delete
596 Bytes
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)