Download handler.py from cortex-agent-llc/kodiak-small-v2-preview: direct link, hf CLI and curl.
- Browser
- Download file 948 Bytes
-
https://huggingface.co/cortex-agent-llc/kodiak-small-v2-preview/resolve/main/handler.py
- Command line
-
hf download hf://cortex-agent-llc/kodiak-small-v2-preview/handler.py
-
curl -L -o handler.py https://huggingface.co/cortex-agent-llc/kodiak-small-v2-preview/resolve/main/handler.py
948 Bytes
| """Hugging Face Inference Endpoints handler for Kodiak (copied into every exported model folder). | |
| Deploy: model page -> Deploy -> Inference Endpoints (CPU is enough; ~80 ms per request on 8 cores). The endpoint installs | |
| `requirements.txt` from the repo, then calls EndpointHandler for each request. | |
| Request body (one request or a list): | |
| {"inputs": {"state": "...", "questions": [...], "options": {...}}} | |
| {"inputs": [{"state": ..., "questions": [...]}, ...]} | |
| Response: the Kodiak Response for each request (see the repo's schema/ folder). | |
| """ | |
| from typing import Any | |
| from kodiak_s1.hub import Kodiak | |
| class EndpointHandler: | |
| def __init__(self, path: str = ""): | |
| self.kodiak = Kodiak.from_pretrained(path or ".") | |
| def __call__(self, data: dict[str, Any]) -> list[dict]: | |
| inputs = data.get("inputs", data) | |
| requests = inputs if isinstance(inputs, list) else [inputs] | |
| return self.kodiak.answer(requests) | |