Files
Byparr/main.py
T
renovate[bot]andThePhaseless 93ffe3ec0f fix(deps): pin dependencies (#446)
* fix(deps): pin dependencies

* fix: stop passing log_level to FastAPI

FastAPI never had a log_level parameter; it went into **extra and was
ignored until 0.162 removed **extra, where it raises TypeError at import.
uvicorn.run already receives the log level.

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: ThePhaseless <kukubaorch@gmail.com>
2026-11-05 16:56:43 +01:00

40 lines
1.0 KiB
Python

from __future__ import annotations
import logging
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.gzip import GZipMiddleware
from src.consts import HOST, LOG_LEVEL, PORT, VERSION
from src.endpoints import router
from src.middlewares import LogRequest
from src.owui import router as owui_router
from src.utils import logger, warm_up
LOG_LEVEL_NAME = logging.getLevelName(LOG_LEVEL).lower()
logger.info("Using version %s", VERSION)
logger.info("Log level set to %s", LOG_LEVEL_NAME)
@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncGenerator[None]:
"""Fetch the GeoIP database before uvicorn opens the port."""
await warm_up()
yield
app = FastAPI(debug=LOG_LEVEL == logging.DEBUG, lifespan=lifespan)
app.add_middleware(GZipMiddleware)
app.add_middleware(LogRequest)
app.include_router(router=router)
app.include_router(router=owui_router)
if __name__ == "__main__":
uvicorn.run(app, host=HOST, port=PORT, log_level=LOG_LEVEL_NAME)