Enable multiple llms

This commit is contained in:
Niels Geens
2024-11-22 15:05:54 +01:00
parent bbb88f39e8
commit 8766a945c0
28 changed files with 972 additions and 525 deletions

32
sia/web/static.py Normal file
View File

@@ -0,0 +1,32 @@
from aiohttp import web
import mimetypes
from ..config import Config
mimetypes.add_type("application/javascript", ".js")
mimetypes.add_type("application/javascript", ".jsx")
mimetypes.add_type("text/javascript", ".js")
mimetypes.add_type("text/javascript", ".jsx")
class Static:
def __init__(self, app: web.Application, config: Config):
self._config = config
app.router.add_get("/", self._serve_index)
app.router.add_static("/static/", self._config.static_files, show_index=False)
app.router.add_static("/assets/", self._config.static_files / "assets", show_index=False)
app.router.add_get("/{path:.*}", self._serve_index)
async def _serve_index(self, request: web.Request) -> web.Response:
"""Serve the React application HTML for any unmatched routes."""
index_path = self._config.static_files / "index.html"
if not index_path.exists():
raise web.HTTPNotFound()
with open(index_path, "r") as f:
html_content = f.read()
return web.Response(
text=html_content,
content_type="text/html"
)