50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
from contextlib import asynccontextmanager
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from .core import get_settings, logger
|
|
from .api import translate_router, admin_router, provider_router, stats_router
|
|
from .services import cache_service, rate_limit_service, llm_service, stats_service
|
|
|
|
settings = get_settings()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
logger.info("Starting up...")
|
|
await cache_service.connect()
|
|
await rate_limit_service.connect()
|
|
await llm_service.connect()
|
|
await stats_service.connect()
|
|
yield
|
|
logger.info("Shutting down...")
|
|
await cache_service.disconnect()
|
|
await rate_limit_service.disconnect()
|
|
await llm_service.disconnect()
|
|
await stats_service.disconnect()
|
|
|
|
|
|
app = FastAPI(
|
|
title="AI Translator API",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(translate_router)
|
|
app.include_router(admin_router)
|
|
app.include_router(provider_router)
|
|
app.include_router(stats_router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok"}
|