squadds-ml-inference-api / tests /test_contract.py
shanto268's picture
SQuADDS ML API 2: squadds 53ec2b11, registry 1dbf099a
55ce00a verified
Raw History Blame Contribute Delete
1.1 kB
"""Every servable model with an example: example request -> example response within its rtol."""
import base64
import json
import pytest
from conftest import CAP, ROOT
from test_legacy import close
def run(client, model_id, headers=None):
ex = json.loads((ROOT / f"examples/{model_id}.json").read_text())
body = dict(ex["request"])
if "file" in ex:
body["inputs"] = {**body["inputs"], "file_base64": base64.b64encode((ROOT / ex["file"]).read_bytes()).decode()}
r = client.post(f"/v1/models/{model_id}/predict", json=body, headers=headers or {})
assert r.status_code == 200, r.text
got = r.json()
for k in ("model_id", "family", "revision", "outputs", "metadata"):
close(ex["response"][k], got[k], ex.get("rtol", 1e-5))
assert set(got) == {"model_id", "family", "revision", "outputs", "metadata", "timing_s", "cached"}
def test_contract_public(client):
run(client, "transmon_cross_hamiltonian_inverse")
@pytest.mark.parametrize("model_id", CAP)
def test_contract_gated(gated_client, auth, model_id):
run(gated_client, model_id, auth)