from fastapi import FastAPI from db.models import Base from db.database import engine from api.router.book import db_conn from llama_index.core import set_global_handler from dotenv import load_dotenv import os load_dotenv() async def startup() -> None: Base.metadata.create_all(engine) print("table added") await db_conn.connect() os.environ["LANGFUSE_SECRET_KEY"] = os.getenv("LANGFUSE_SECRET_KEY") os.environ["LANGFUSE_PUBLIC_KEY"] = os.getenv("LANGFUSE_PUBLIC_KEY") os.environ["LANGFUSE_HOST"] = os.getenv("LANGFUSE_HOST") set_global_handler("langfuse") async def shutdown() -> None: await db_conn.disconnect() def register_events(app: FastAPI) -> FastAPI: app.add_event_handler("startup", startup) app.add_event_handler("shutdown", shutdown) return app