Files
spark-control/image/app/health.py
T
Grant 2ba3da55b1 0.1.0:3 - Show Public Key layout + /api/endpoints service-discovery
- showPublicKey now uses result.group: install command and raw key are each their own one-click copy box; description is brief
- /api/endpoints returns stable shape { vllm, parakeet, magpie } with base_url + model + ready, for other LAN services to consume without hardcoding Spark IPs
- health.py: parakeet/magpie now also expose base_url
- README: documented /api/endpoints shape
2026-05-12 10:52:57 -05:00

68 lines
2.4 KiB
Python

from __future__ import annotations
import httpx
from .config import Settings
_TIMEOUT = 3.0
async def check_vllm(settings: Settings) -> dict:
base_url = (
f"http://{settings.spark1_host}:{settings.vllm_port}/v1"
if settings.spark1_host
else None
)
if not settings.spark1_host:
return {"ok": False, "error": "spark1 not configured", "base_url": base_url}
try:
async with httpx.AsyncClient(timeout=_TIMEOUT) as c:
r = await c.get(f"http://{settings.spark1_host}:{settings.vllm_port}/v1/models")
r.raise_for_status()
ids = [m["id"] for m in r.json().get("data", [])]
return {
"ok": True,
"current_model": ids[0] if ids else None,
"all": ids,
"base_url": base_url,
}
except Exception as e:
return {"ok": False, "error": str(e), "base_url": base_url}
async def check_parakeet(settings: Settings) -> dict:
base_url = (
f"http://{settings.spark2_host}:{settings.parakeet_port}"
if settings.spark2_host
else None
)
if not settings.spark2_host:
return {"ok": False, "error": "spark2 not configured", "base_url": base_url}
try:
async with httpx.AsyncClient(timeout=_TIMEOUT) as c:
r = await c.get(f"http://{settings.spark2_host}:{settings.parakeet_port}/health")
r.raise_for_status()
return {"ok": True, "detail": r.json(), "base_url": base_url}
except Exception as e:
return {"ok": False, "error": str(e), "base_url": base_url}
async def check_magpie(settings: Settings) -> dict:
base_url = (
f"http://{settings.spark2_host}:{settings.magpie_port}"
if settings.spark2_host
else None
)
if not settings.spark2_host:
return {"ok": False, "error": "spark2 not configured", "base_url": base_url}
try:
async with httpx.AsyncClient(timeout=_TIMEOUT) as c:
r = await c.get(f"http://{settings.spark2_host}:{settings.magpie_port}/v1/health/ready")
r.raise_for_status()
return {
"ok": True,
"detail": r.json() if r.headers.get("content-type", "").startswith("application/json") else r.text,
"base_url": base_url,
}
except Exception as e:
return {"ok": False, "error": str(e), "base_url": base_url}