Files
forgeway/scripts/probe_cloud_params.py
T
Dolon (Agent)andClaude Opus 5 3155d4a230 forgeway 0.1.1 — per-cluster OpenAI-compatible LLM router
Two endpoints over forge's Ollama gpt-oss:120b:
  /local-optimistic/v1  forge, else cloud gpt-5.4-mini
  /local-strict/v1      forge, else a clean 503 the caller handles

Discovery, not configuration: each instance probes an ordered candidate list
(stable DNS name, then the Lounge and future Serenity literals) concurrently but
in priority order, so the happy path is one round trip and silicon's move to
Serenity needs no rewrite.

/healthz runs a real 1-token completion — forge can be up with Ollama stopped.
Liveness/readiness are deliberately NOT forge-gated: otherwise k8s would evict
the pods during an outage and callers would get a connection failure instead of
the promised 503, and Kuma could not tell "forge down" from "router gone".

max_tokens/max_completion_tokens are translated per backend: Ollama accepts only
the former, gpt-5.4-mini rejects it outright.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 14:30:14 +00:00

46 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Probe which OpenAI chat parameters gpt-5.4-mini accepts.
Reads the key from the environment and never prints it.
"""
import json
import os
import sys
import urllib.error
import urllib.request
KEY = os.environ.get("OPENAI_API_KEY", "")
MODEL = os.environ.get("FORGEWAY_CLOUD_MODEL", "gpt-5.4-mini")
if not KEY:
sys.exit("OPENAI_API_KEY not present in the environment")
CASES = {
"max_completion_tokens only": {"max_completion_tokens": 16},
"max_tokens only": {"max_tokens": 16},
"temperature=0": {"max_completion_tokens": 16, "temperature": 0},
"temperature=1": {"max_completion_tokens": 16, "temperature": 1},
"top_p=0.9": {"max_completion_tokens": 16, "top_p": 0.9},
"stream=true": {"max_completion_tokens": 16, "stream": True},
}
for label, extra in CASES.items():
body = {"model": MODEL, "messages": [{"role": "user", "content": "say PONG"}], **extra}
req = urllib.request.Request(
"https://api.openai.com/v1/chat/completions",
data=json.dumps(body).encode(),
headers={"Content-Type": "application/json", "Authorization": f"Bearer {KEY}"},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=60) as resp:
print(f"{label:28s} -> {resp.status} OK")
except urllib.error.HTTPError as exc:
detail = exc.read().decode("utf-8", "replace")
try:
detail = json.loads(detail)["error"]["message"]
except Exception:
detail = detail[:160]
print(f"{label:28s} -> {exc.code} {detail}")
except Exception as exc: # noqa: BLE001
print(f"{label:28s} -> ERROR {type(exc).__name__}: {exc}")