Spaces:
Sleeping
Sleeping
| 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} | |