Download squadds_ml_api/adapters/base.py from SQuADDS/squadds-ml-inference-api: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/SQuADDS/squadds-ml-inference-api/resolve/main/squadds_ml_api/adapters/base.py
- Command line
-
hf download hf://spaces/SQuADDS/squadds-ml-inference-api/squadds_ml_api/adapters/base.py
-
curl -L -o base.py https://huggingface.co/spaces/SQuADDS/squadds-ml-inference-api/resolve/main/squadds_ml_api/adapters/base.py
1.04 kB
| """The adapter protocol (duck-typed; tests/test_registry.py enforces it). | |
| class Adapter: | |
| input_kind: "json" | "file" json: inputs is an object (or a list when batch = True); file: one uploaded file + inputs | |
| InputModel: pydantic model request schema of `inputs` (drives /docs, validation and the tool schema) | |
| OptionsModel: pydantic model optional, schema of `options` | |
| batch: bool optional, inputs may be a list of objects | |
| def __init__(self, model_id, root, config, limits) root = verified local weights | |
| def describe(self) -> dict merged into GET /v1/models/{id} | |
| def predict(self, inputs, file=None, options=None) -> {"outputs": {...}, "metadata": {...}, "timing_s": {...}} | |
| def warm(self, example: Path) -> None optional | |
| predict validates its own raw inputs: pydantic.ValidationError -> 422, ValueError -> 400, a ValueError with | |
| `too_large = True` -> 413, anything else -> 500. | |
| """ | |
| REQUIRED = ("input_kind", "describe", "predict") | |