Spaces:
Runtime error
Runtime error
Download api.py from SubZtep/ai-hello-world: direct link, hf CLI and curl.
- Browser
- Download file 666 Bytes
-
https://huggingface.co/spaces/SubZtep/ai-hello-world/resolve/main/api.py
- Command line
-
hf download hf://spaces/SubZtep/ai-hello-world/api.py
-
curl -L -o api.py https://huggingface.co/spaces/SubZtep/ai-hello-world/resolve/main/api.py
666 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from ai_engine import generate | |
| app = FastAPI(title="Hello World AI") | |
| # VERY simple in-memory store - now storing tuples (user_msg, assistant_msg) | |
| sessions: dict[str, list[tuple[str, str]]] = {} | |
| class ChatRequest(BaseModel): | |
| session_id: str | |
| message: str | |
| class ChatResponse(BaseModel): | |
| reply: str | |
| def chat(req: ChatRequest): | |
| history = sessions.setdefault(req.session_id, []) | |
| reply = generate(req.message, history) | |
| # Store as tuple (user_msg, assistant_msg) | |
| history.append((req.message, reply)) | |
| return {"reply": reply} | |