from __future__ import annotations from fastapi import FastAPI, HTTPException from schemas import HealthResponse, PredictRequest, PredictResponse from service import MoiraiService app = FastAPI(title="Moirai Space", version="0.1.0") service = MoiraiService() @app.get("/health", response_model=HealthResponse) def health() -> HealthResponse: return service.health() @app.get("/") def root() -> dict[str, str]: return {"service": "moirai", "status": "ok"} @app.post("/predict", response_model=PredictResponse) def predict(payload: PredictRequest) -> PredictResponse: try: return service.predict(payload) except ValueError as exc: raise HTTPException(status_code=400, detail=str(exc)) from exc except RuntimeError as exc: raise HTTPException(status_code=503, detail=str(exc)) from exc except Exception as exc: # pragma: no cover raise HTTPException(status_code=500, detail=f"prediction_failed: {exc}") from exc