Initial lightweight AI agent admin
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.api.ai import router as ai_router
|
||||
from app.api.auth import router as auth_router
|
||||
from app.api.core import router as core_router
|
||||
from app.core.config import settings
|
||||
from app.core.database import AsyncSessionLocal, Base, engine
|
||||
from app.models import * # noqa: F401,F403
|
||||
from app.services.seed import seed_database
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
async with AsyncSessionLocal() as db:
|
||||
await seed_database(db)
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(title=settings.app_name, version="0.1.0", lifespan=lifespan)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"] if settings.cors_origins == "*" else settings.cors_origins.split(","),
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(auth_router, prefix="/api")
|
||||
app.include_router(core_router, prefix="/api")
|
||||
app.include_router(ai_router, prefix="/api")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"status": "ok", "app": settings.app_name}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run("app.main:app", host=settings.app_host, port=settings.app_port, reload=settings.debug)
|
||||
Reference in New Issue
Block a user