start frontend

This commit is contained in:
Matteo Rosati
2026-02-18 13:27:39 +01:00
parent 6e8c8ceb38
commit 3e6fefabbd
9 changed files with 1085 additions and 9 deletions

31
app.py Normal file
View File

@@ -0,0 +1,31 @@
from fastapi import FastAPI, WebSocket
from fastapi.templating import Jinja2Templates
from fastapi import Request
from fastapi.staticfiles import StaticFiles
from chain import full_chain
app = FastAPI()
templates = Jinja2Templates(directory="templates")
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/")
def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
try:
while True:
message = await websocket.receive_text()
await websocket.send_json({"type": "start"})
async for chunk in full_chain.astream(message):
await websocket.send_json({"type": "chunk", "data": chunk})
await websocket.send_json({"type": "end"})
except Exception:
pass