fix: fail AI checks on invalid OmniRoute routes
This commit is contained in:
parent
162bee22d4
commit
3963b33128
|
|
@ -585,8 +585,43 @@ with open(output_path, "w", encoding="utf-8") as fh:
|
|||
fh.write(f"AI_STACK_AGENT_SMART_MODEL={smart_model}\n")
|
||||
fh.write(f"AI_STACK_AGENT_FAST_DIRECT_MODEL={direct_fast}\n")
|
||||
fh.write(f"AI_STACK_AGENT_SMART_DIRECT_MODEL={direct_smart}\n")
|
||||
fh.write("AI_STACK_MODEL_VALIDATION_STATUS=ok\n")
|
||||
fh.write(f"AI_STACK_OPENROUTER_FREE_COUNT={len(routes.get('openrouter_free') or [])}\n")
|
||||
fh.write(f"AI_STACK_NVIDIA_MODEL_COUNT={len(routes.get('nvidia') or [])}\n")
|
||||
validation = routes.get("validation") or {}
|
||||
fh.write(f"AI_STACK_VALIDATED_FAST_COUNT={validation.get('fast_valid_count', len(fast))}\n")
|
||||
fh.write(f"AI_STACK_VALIDATED_SMART_COUNT={validation.get('smart_valid_count', len(smart))}\n")
|
||||
PY
|
||||
chmod 0600 "${output_file}"
|
||||
}
|
||||
|
||||
write_invalid_model_routes_file() {
|
||||
local routes_json="$1"
|
||||
local output_file="$2"
|
||||
|
||||
python3 - "${routes_json}" "${output_file}" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
routes_path, output_path = sys.argv[1:3]
|
||||
try:
|
||||
with open(routes_path, encoding="utf-8") as fh:
|
||||
routes = json.load(fh)
|
||||
except Exception:
|
||||
routes = {}
|
||||
|
||||
validation = routes.get("validation") or {}
|
||||
with open(output_path, "w", encoding="utf-8") as fh:
|
||||
fh.write("# Generated by jeannie deploy-ai-stack. Do not commit.\n")
|
||||
fh.write("AI_STACK_AGENT_FAST_MODEL=\n")
|
||||
fh.write("AI_STACK_AGENT_SMART_MODEL=\n")
|
||||
fh.write("AI_STACK_AGENT_FAST_DIRECT_MODEL=\n")
|
||||
fh.write("AI_STACK_AGENT_SMART_DIRECT_MODEL=\n")
|
||||
fh.write("AI_STACK_MODEL_VALIDATION_STATUS=failed\n")
|
||||
fh.write(f"AI_STACK_OPENROUTER_FREE_COUNT={len(routes.get('openrouter_free') or [])}\n")
|
||||
fh.write(f"AI_STACK_NVIDIA_MODEL_COUNT={len(routes.get('nvidia') or [])}\n")
|
||||
fh.write(f"AI_STACK_VALIDATED_FAST_COUNT={validation.get('fast_valid_count', 0)}\n")
|
||||
fh.write(f"AI_STACK_VALIDATED_SMART_COUNT={validation.get('smart_valid_count', 0)}\n")
|
||||
PY
|
||||
chmod 0600 "${output_file}"
|
||||
}
|
||||
|
|
@ -624,6 +659,7 @@ print(
|
|||
sys.exit(0 if fast or smart else 1)
|
||||
PY
|
||||
then
|
||||
write_invalid_model_routes_file "${validated_routes_json}" "${MODEL_ROUTES_FILE}"
|
||||
echo "No OmniRoute models passed runtime validation; refusing to keep or create stale AI routes." >&2
|
||||
echo "Check provider quota/cooldown or seed a known-good provider key, then rerun ./jeannie deploy-ai-stack." >&2
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -2855,9 +2855,18 @@ ai_check() {
|
|||
if [[ -s "${routes_file}" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
. "${routes_file}"
|
||||
printf '%-28s ok - %s\n' "ai stack routes" "${routes_file}"
|
||||
if [[ "${AI_STACK_MODEL_VALIDATION_STATUS:-ok}" == "ok" ]]; then
|
||||
printf '%-28s ok - %s\n' "ai stack routes" "${routes_file}"
|
||||
else
|
||||
printf '%-28s failed validation - rerun ./jeannie deploy-ai-stack after fixing providers\n' "ai stack routes"
|
||||
failures=$((failures + 1))
|
||||
fi
|
||||
printf '%-28s %s\n' "agent fast model" "${AI_STACK_AGENT_FAST_MODEL:-unset}"
|
||||
printf '%-28s %s\n' "agent smart model" "${AI_STACK_AGENT_SMART_MODEL:-unset}"
|
||||
printf '%-28s fast=%s smart=%s\n' "validated routes" "${AI_STACK_VALIDATED_FAST_COUNT:-unknown}" "${AI_STACK_VALIDATED_SMART_COUNT:-unknown}"
|
||||
if [[ -z "${AI_STACK_AGENT_FAST_MODEL:-}" || -z "${AI_STACK_AGENT_SMART_MODEL:-}" ]]; then
|
||||
failures=$((failures + 1))
|
||||
fi
|
||||
if [[ "${provider}" == "ollama" && -n "${AI_STACK_AGENT_FAST_MODEL:-}" ]]; then
|
||||
provider="omniroute"
|
||||
endpoint="${LAB_AI_GATEWAY_URL:-http://127.0.0.1:20128/v1}"
|
||||
|
|
@ -2871,11 +2880,54 @@ ai_check() {
|
|||
if [[ "${provider,,}" == "omniroute" || "${provider,,}" == "openai" ]]; then
|
||||
if curl -sS -o /dev/null -w '%{http_code}' --max-time 5 "${endpoint%/}/models" 2>/dev/null | grep -Eq '^(200|401)$'; then
|
||||
printf '%-28s ok - %s\n' "omniroute endpoint" "${endpoint}"
|
||||
printf '%-28s ok - %s\n' "omniroute model" "${model}"
|
||||
else
|
||||
printf '%-28s unreachable - %s\n' "omniroute endpoint" "${endpoint}"
|
||||
failures=$((failures + 1))
|
||||
fi
|
||||
if [[ -n "${model}" ]] && python3 - "${endpoint}" "${model}" "${OPENAI_API_KEY:-${LAB_AI_GATEWAY_API_KEY:-sk_omniroute}}" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
endpoint, model, api_key = sys.argv[1:4]
|
||||
payload = {
|
||||
"model": model,
|
||||
"messages": [{"role": "user", "content": "Return only: ok"}],
|
||||
"stream": False,
|
||||
"max_tokens": 8,
|
||||
"temperature": 0,
|
||||
}
|
||||
headers = {"Content-Type": "application/json", "Accept": "application/json"}
|
||||
if api_key:
|
||||
headers["Authorization"] = f"Bearer {api_key}"
|
||||
request = urllib.request.Request(
|
||||
f"{endpoint.rstrip('/')}/chat/completions",
|
||||
data=json.dumps(payload).encode("utf-8"),
|
||||
headers=headers,
|
||||
method="POST",
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=45) as response:
|
||||
data = json.load(response)
|
||||
except urllib.error.HTTPError as exc:
|
||||
print(f"HTTP {exc.code}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
except Exception as exc:
|
||||
print(type(exc).__name__, file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
choices = data.get("choices") or []
|
||||
content = ""
|
||||
if choices:
|
||||
content = ((choices[0].get("message") or {}).get("content") or "").strip()
|
||||
raise SystemExit(0 if content else 1)
|
||||
PY
|
||||
then
|
||||
printf '%-28s ok - %s\n' "omniroute model" "${model}"
|
||||
else
|
||||
printf '%-28s failed chat completion - %s\n' "omniroute model" "${model:-unset}"
|
||||
failures=$((failures + 1))
|
||||
fi
|
||||
elif curl -fsS --max-time 5 "${endpoint%/}/api/tags" >/dev/null 2>&1; then
|
||||
printf '%-28s ok - %s\n' "ollama endpoint" "${endpoint}"
|
||||
if python3 - "${endpoint}" "${model}" <<'PY'
|
||||
|
|
|
|||
|
|
@ -5428,12 +5428,21 @@ deploy_ai_tools() {
|
|||
if [[ -s "${model_routes_file}" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
. "${model_routes_file}"
|
||||
if [[ "${AI_STACK_MODEL_VALIDATION_STATUS:-ok}" != "ok" ]]; then
|
||||
echo "AI stack model routes failed runtime validation; rerun ./jeannie deploy-ai-stack after fixing provider quota/config." >&2
|
||||
exit 1
|
||||
fi
|
||||
fast_model="${LAB_AI_TOOLS_FAST_MODEL:-${AI_STACK_AGENT_FAST_MODEL:-${fast_model}}}"
|
||||
smart_model="${LAB_AI_TOOLS_SMART_MODEL:-${AI_STACK_AGENT_SMART_MODEL:-${smart_model}}}"
|
||||
else
|
||||
echo "AI stack model routes are missing at ${model_routes_file}; run ./jeannie deploy-ai-stack first." >&2
|
||||
fi
|
||||
|
||||
if [[ -z "${fast_model}" || -z "${smart_model}" ]]; then
|
||||
echo "AI stack model routes are empty; run ./jeannie deploy-ai-stack and ensure at least one OmniRoute model validates." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Configuring bare-metal AI tools for OmniRoute at ${endpoint}..."
|
||||
install -d -m 0755 "${bin_dir}"
|
||||
sudo install -d -m 0750 -o "$(id -u)" -g "$(id -g)" "${install_dir}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue