feat(ift): EventHub AI Router stack for Zed
FastAPI gateway with A/B/C lane orchestration, LiteLLM proxy config, Swarm stack (postgres, redis, VPN off-by-default), deploy/smoke/audit scripts.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
# Daily Novita pricing/model audit — compare model_matrix.yaml vs /v1/models
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
[[ -f .env ]] && source .env
|
||||
set +a
|
||||
|
||||
API_KEY="${NOVITA_API_KEY:?NOVITA_API_KEY required}"
|
||||
LOG_DIR="${AUDIT_LOG_DIR:-/var/log/ai-router}"
|
||||
DATE="$(date +%Y-%m-%d)"
|
||||
REPORT="${LOG_DIR}/audit-${DATE}.json"
|
||||
THRESHOLD="${PRICE_DRIFT_THRESHOLD_PCT:-10}"
|
||||
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
MODELS_JSON="$(curl -sf "https://api.novita.ai/openai/v1/models" \
|
||||
-H "Authorization: Bearer ${API_KEY}")"
|
||||
|
||||
export ROOT MODELS_JSON REPORT THRESHOLD
|
||||
python3 <<'PY'
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
root = Path(os.environ["ROOT"])
|
||||
matrix = yaml.safe_load((root / "config/model_matrix.yaml").read_text(encoding="utf-8"))
|
||||
catalog = json.loads(os.environ["MODELS_JSON"])
|
||||
threshold = float(os.environ.get("THRESHOLD", "10"))
|
||||
|
||||
by_id = {m["id"]: m for m in catalog.get("data", [])}
|
||||
issues = []
|
||||
checked = 0
|
||||
|
||||
for name, cfg in matrix.get("models", {}).items():
|
||||
novita = cfg.get("novita", "")
|
||||
model_id = novita.replace("novita/", "", 1) if novita.startswith("novita/") else novita
|
||||
if not model_id:
|
||||
continue
|
||||
checked += 1
|
||||
if model_id not in by_id:
|
||||
issues.append({"model": name, "novita_id": model_id, "severity": "critical", "msg": "missing from catalog"})
|
||||
|
||||
report = {
|
||||
"date": os.environ.get("DATE", ""),
|
||||
"checked": checked,
|
||||
"issues": issues,
|
||||
"catalog_count": len(by_id),
|
||||
}
|
||||
report_path = Path(os.environ["REPORT"])
|
||||
report_path.write_text(json.dumps(report, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
if any(i["severity"] == "critical" for i in issues):
|
||||
print(f"CRITICAL: {len(issues)} issues — see {report_path}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
if issues:
|
||||
print(f"WARN: {len(issues)} issues — see {report_path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
print(f"OK: {checked} models, report {report_path}")
|
||||
PY
|
||||
Reference in New Issue
Block a user