Migrated from the rl-toolkit snapshot deployed for the 2026-09-15 production run (toolkit e191cf1 plus uncommitted changes). PRIME-RL is now a submodule on dphn/prime-rl@trinity; the v0 envs, parity tests, OPD experiment, and old configs are not carried over.
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""Verify public API auth and a real completion without logging credentials."""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
url = sys.argv[1].rstrip("/")
|
|
|
|
|
|
def request(path, authenticated=True, data=None):
|
|
headers = {"Content-Type": "application/json"}
|
|
if authenticated:
|
|
headers["Authorization"] = "Bearer " + os.environ["VLLM_API_KEY"]
|
|
req = urllib.request.Request(
|
|
url + path, headers=headers, data=json.dumps(data).encode() if data else None
|
|
)
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=180) as response:
|
|
return response.status, json.load(response)
|
|
except urllib.error.HTTPError as error:
|
|
return error.code, {"error": error.reason}
|
|
|
|
|
|
status, _ = request("/models", authenticated=False)
|
|
assert status == 401, ("Unauthenticated endpoint must reject access", status)
|
|
status, models = request("/models")
|
|
assert status == 200, status
|
|
model = "google/gemma-4-26B-A4B-it"
|
|
assert model in [item["id"] for item in models["data"]]
|
|
status, completion = request(
|
|
"/chat/completions",
|
|
data={
|
|
"model": model,
|
|
"messages": [{"role": "user", "content": "Reply with the word ready."}],
|
|
"max_tokens": 32,
|
|
"temperature": 0,
|
|
"chat_template_kwargs": {"enable_thinking": False},
|
|
},
|
|
)
|
|
assert status == 200, (status, completion)
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"authenticated_models": 200,
|
|
"unauthenticated_models": 401,
|
|
"completion": completion["choices"][0]["message"],
|
|
"usage": completion["usage"],
|
|
}
|
|
)
|
|
)
|