app/main.py aktualisiert
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
This commit is contained in:
parent
43e77c4c6b
commit
c5972be618
126
app/main.py
126
app/main.py
|
|
@ -1,73 +1,23 @@
|
|||
"""
|
||||
app/main.py — mindnet API bootstrap (WP-04 Hooks)
|
||||
|
||||
Zweck:
|
||||
Startpunkt der FastAPI-Anwendung: Router-Registrierung und Healthcheck.
|
||||
Ergänzt um optionale WP-04 Router (Graph/Retriever), falls vorhanden.
|
||||
Kompatibilität:
|
||||
Python 3.12+; FastAPI 0.110+ (getestet lokal)
|
||||
Version:
|
||||
0.4.1 (WP-04 Hooks erweitert: Feature-Flags & /admin/features; bestehende Routen unverändert)
|
||||
Stand:
|
||||
2025-10-07
|
||||
Bezug:
|
||||
Handbuch & Knowledge Design (WP-03/04)
|
||||
Umgebung:
|
||||
Siehe app/config.py (QDRANT_URL, MINDNET_PREFIX, usw.)
|
||||
Nutzung:
|
||||
uvicorn app.main:app --reload --port 8000
|
||||
Änderungsverlauf:
|
||||
0.4.1 (2025-10-07) – Feature-Flags für dynamische WP-04-Router + /admin/features ergänzt.
|
||||
0.4.0 (2025-10-06) – /admin/meta ergänzt; optionale Einbindung von graph/query/admin Routern.
|
||||
0.3.x (vorher) – Basisversion laut bereitgestellter Datei.
|
||||
|
||||
Hinweise:
|
||||
Bestehende Routen/Funktionen bleiben unverändert.
|
||||
Version: 0.4.2 • Stand: 2025-10-07
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import FastAPI
|
||||
from .config import get_settings
|
||||
from .routers.embed_router import router as embed_router
|
||||
from .routers.qdrant_router import router as qdrant_router
|
||||
|
||||
|
||||
def _maybe_include_wp04(app: FastAPI) -> None:
|
||||
"""
|
||||
WP-04 Router dynamisch einbinden, ohne harte Abhängigkeit.
|
||||
Ergänzung: setzt app.state.features['wp04']-Flags, damit Admin/Monitoring
|
||||
sichtbar machen kann, was tatsächlich geladen wurde.
|
||||
"""
|
||||
# Initialisiere Feature-Flags
|
||||
if not hasattr(app.state, "features"):
|
||||
app.state.features = {}
|
||||
app.state.features.setdefault("wp04", {"graph": False, "query": False, "admin": False})
|
||||
|
||||
# Graph
|
||||
try:
|
||||
from .routers.graph import router as graph_router # type: ignore
|
||||
app.include_router(graph_router, prefix="/graph", tags=["graph"])
|
||||
app.state.features["wp04"]["graph"] = True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Query
|
||||
try:
|
||||
from .routers.query import router as query_router # type: ignore
|
||||
app.include_router(query_router, prefix="/query", tags=["query"])
|
||||
app.state.features["wp04"]["query"] = True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Admin (optional)
|
||||
try:
|
||||
from .routers.admin import router as admin_router # type: ignore
|
||||
app.include_router(admin_router, prefix="/admin", tags=["admin"])
|
||||
app.state.features["wp04"]["admin"] = True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# WP-04 Router:
|
||||
from .routers.query import router as query_router
|
||||
from .routers.graph import router as graph_router
|
||||
from .routers.tools import router as tools_router
|
||||
# Optional:
|
||||
try:
|
||||
from .routers.admin import router as admin_router
|
||||
except Exception:
|
||||
admin_router = None
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
app = FastAPI(title="mindnet API", version="0.1.0")
|
||||
|
|
@ -75,61 +25,19 @@ def create_app() -> FastAPI:
|
|||
|
||||
@app.get("/healthz")
|
||||
def healthz():
|
||||
"""Basis-Liveness-Check (unverändert)."""
|
||||
return {"status": "ok", "qdrant": s.QDRANT_URL, "prefix": s.COLLECTION_PREFIX}
|
||||
|
||||
# Admin-Metadaten (WP-04, unverändert)
|
||||
@app.get("/admin/meta")
|
||||
def admin_meta():
|
||||
# Import lokal, damit fehlende Module nicht beim Start stören
|
||||
meta = {}
|
||||
try:
|
||||
import app.main as _m
|
||||
meta["main"] = getattr(_m, "__doc__", "").splitlines()[0:1]
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
import app.config as _c
|
||||
meta["config"] = {
|
||||
"QDRANT_URL": s.QDRANT_URL,
|
||||
"COLLECTION_PREFIX": s.COLLECTION_PREFIX,
|
||||
"VECTOR_SIZE": s.VECTOR_SIZE,
|
||||
"DISTANCE": s.DISTANCE,
|
||||
"MODEL_NAME": s.MODEL_NAME,
|
||||
"RETRIEVER": {
|
||||
"W_SEM": getattr(s, "RETRIEVER_W_SEM", 0.70),
|
||||
"W_EDGE": getattr(s, "RETRIEVER_W_EDGE", 0.25),
|
||||
"W_CENT": getattr(s, "RETRIEVER_W_CENT", 0.05),
|
||||
"TOP_K": getattr(s, "RETRIEVER_TOP_K", 10),
|
||||
"EXPAND_DEPTH": getattr(s, "RETRIEVER_EXPAND_DEPTH", 1),
|
||||
},
|
||||
}
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
import app.core.qdrant_points as _qp
|
||||
meta["qdrant_points"] = getattr(_qp, "__doc__", "").splitlines()[0:1]
|
||||
except Exception:
|
||||
pass
|
||||
return {"meta": meta}
|
||||
|
||||
# NEU: Features-/Readiness-Ansicht (rein ergänzend)
|
||||
@app.get("/admin/features")
|
||||
def admin_features():
|
||||
"""
|
||||
Liefert die dynamisch gesetzten Feature-Flags für WP-04 Router
|
||||
(graph/query/admin), ohne bestehende Endpunkte zu beeinflussen.
|
||||
"""
|
||||
features = getattr(app.state, "features", {})
|
||||
return {"features": features}
|
||||
|
||||
# Bestehende Router (unverändert)
|
||||
app.include_router(embed_router)
|
||||
app.include_router(qdrant_router)
|
||||
|
||||
# WP-04 Router ggf. dynamisch einbinden
|
||||
_maybe_include_wp04(app)
|
||||
# WP-04 Endpunkte
|
||||
app.include_router(query_router, prefix="/query", tags=["query"])
|
||||
app.include_router(graph_router, prefix="/graph", tags=["graph"])
|
||||
app.include_router(tools_router, prefix="/tools", tags=["tools"])
|
||||
if admin_router:
|
||||
app.include_router(admin_router, prefix="/admin", tags=["admin"])
|
||||
|
||||
return app
|
||||
|
||||
|
||||
app = create_app()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user