graph
This commit is contained in:
@@ -49,6 +49,7 @@ from ont_platform.api.product_backend import include_product_backend # noqa: E4
|
||||
platform_config = importlib.import_module("ont_platform.config")
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
_startup_error: str | None = None
|
||||
|
||||
|
||||
def _resolve_ontocast_version() -> str:
|
||||
@@ -124,8 +125,14 @@ def _include_phase_routers(app: FastAPI) -> None:
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
"""FastAPI lifespan: build ToolBox + workflow once on startup."""
|
||||
global _startup_error
|
||||
settings = platform_config.load_settings()
|
||||
await initialize_app_context(settings)
|
||||
try:
|
||||
await initialize_app_context(settings)
|
||||
_startup_error = None
|
||||
except Exception as exc: # noqa: BLE001
|
||||
_startup_error = str(exc)
|
||||
logger.exception("App context initialization failed; product backend will remain available")
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
@@ -149,8 +156,23 @@ def create_app() -> FastAPI:
|
||||
|
||||
# ─── /health ──────────────────────────────────────────────────────
|
||||
@app.get("/health", tags=["meta"])
|
||||
async def health(ctx: Annotated[AppContext, Depends(get_app_context)]) -> JSONResponse:
|
||||
"""Liveness check. 503 if the LLM isn't wired."""
|
||||
async def health() -> JSONResponse:
|
||||
"""Liveness check for the HTTP service and optional LLM readiness."""
|
||||
settings = platform_config.load_settings()
|
||||
if _startup_error:
|
||||
return JSONResponse(
|
||||
status_code=503,
|
||||
content={
|
||||
"status": "degraded",
|
||||
"error": _startup_error,
|
||||
"platform_version": PLATFORM_VERSION,
|
||||
"ontocast_version": ONTOCAST_VERSION,
|
||||
"phase": int(settings.phase),
|
||||
"storage_backend": settings.storage_backend,
|
||||
},
|
||||
)
|
||||
|
||||
ctx = get_app_context()
|
||||
if ctx.tools.llm is None:
|
||||
return JSONResponse(
|
||||
status_code=503,
|
||||
@@ -170,8 +192,16 @@ def create_app() -> FastAPI:
|
||||
|
||||
# ─── /info ────────────────────────────────────────────────────────
|
||||
@app.get("/info", tags=["meta"])
|
||||
async def info(ctx: Annotated[AppContext, Depends(get_app_context)]) -> JSONResponse:
|
||||
async def info() -> JSONResponse:
|
||||
"""Service-level capabilities (mirrors OntoCast /info semantics)."""
|
||||
settings = platform_config.load_settings()
|
||||
phase = int(settings.phase)
|
||||
storage_backend = settings.storage_backend
|
||||
if not _startup_error:
|
||||
ctx = get_app_context()
|
||||
phase = int(ctx.settings.phase)
|
||||
storage_backend = ctx.settings.storage_backend
|
||||
|
||||
return JSONResponse(
|
||||
status_code=200,
|
||||
content={
|
||||
@@ -185,8 +215,9 @@ def create_app() -> FastAPI:
|
||||
"capabilities": ["text-to-triples", "ontology-extraction"],
|
||||
"input_types": ["text", "json", "pdf", "markdown"],
|
||||
"output_types": ["turtle", "json"],
|
||||
"phase": int(ctx.settings.phase),
|
||||
"storage_backend": ctx.settings.storage_backend,
|
||||
"phase": phase,
|
||||
"storage_backend": storage_backend,
|
||||
"startup_error": _startup_error,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user