Download tests/test_contract.py from SQuADDS/squadds-ml-inference-api: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/SQuADDS/squadds-ml-inference-api/resolve/main/tests/test_contract.py
- Command line
-
hf download hf://spaces/SQuADDS/squadds-ml-inference-api/tests/test_contract.py
-
curl -L -o test_contract.py https://huggingface.co/spaces/SQuADDS/squadds-ml-inference-api/resolve/main/tests/test_contract.py
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") | |
| def test_contract_gated(gated_client, auth, model_id): | |
| run(gated_client, model_id, auth) | |