from dotenv import load_dotenv
load_dotenv()  # Lädt Variablen aus .env in os.environ


from fastapi import FastAPI
from fastapi.responses import JSONResponse
from clients import model, qdrant
from wiki_router import router as wiki_router
from embed_router import router as embed_router
from exercise_router import router as exercise_router

# Version
__version__ = "1.1.6"
print(f"[DEBUG] llm_api.py version {__version__} loaded from {__file__}", flush=True)



# FastAPI-Instanz
app = FastAPI(
    title="KI Trainerassistent API",
    description="Modulare API für Trainingsplanung und MediaWiki-Import",
    version=__version__,
)

# Globaler Fehlerhandler
@app.exception_handler(Exception)
async def unicorn_exception_handler(request, exc):
    return JSONResponse(status_code=500, content={"detail": "Interner Serverfehler."})

# Router einbinden
app.include_router(wiki_router, prefix="/import/wiki")
app.include_router(embed_router)
app.include_router(exercise_router)
