tokz
Client for the Tokz Decisions API: typed answers about text from the open OpenDecision models.
pip install tokz
decide() answers a choice, multilabel, bool or score per question, with a
probability for every option. The text is read by a model on Tokz servers and is not
stored. Each request is billed, so the client never retries one.
import os
from tokz import Tokz
tokz = Tokz(api_key=os.environ["TOKZ_API_KEY"])
out = tokz.decide(
"I was charged twice and the app keeps logging me out.",
{
"queue": {"type": "choice", "options": ["billing", "technical", "account"]},
"priority": {"type": "score", "low": 1, "high": 5},
},
)
r = out["results"][0]
r["queue"]["best"], r["priority"]["score"], out["usage"]["billed_tokens"]
catalog = tokz.list_decision_models()
A 402 raises TokzInsufficientCreditsError; every other failure raises TokzError
with the HTTP status.
Async
from tokz import AsyncTokz
async with AsyncTokz(api_key=...) as tokz:
out = await tokz.decide(texts, {"urgent": {"type": "bool"}})
Same methods, same errors.
Fine-tuned models
A model you fine-tuned in the dashboard already knows its question and labels, so a call names only
the model and the text. The result is always under decision.
out = tokz.decide("support-triage", "I was charged twice.")
out["results"][0]["decision"]["best"]
This runs on Tokz servers and is billed like any decide(). A 503 or 429 carries the wait the
server asked for in err.retry_after, in seconds. The client still never retries.
To run the same model on your own machine, for free, change one word:
pip install "tokz[local]"
out = tokz.decide_local("support-triage", "I was charged twice.")
The first call downloads the model into ~/.cache/tokz on every OS and verifies its checksums. Set
TOKZ_CACHE_DIR to put it elsewhere. After that it needs no network, though it asks the server once
an hour per process whether the model still exists, waiting about a second at most. Deleting a model
in the dashboard stops decide_local within an hour once the machine can reach us, and removes its
cached copy.
For a multi-label model read selected. best names a label even when selected is empty.
AsyncTokz has the same decide_local, on a worker thread. tokz[local] keeps onnxruntime at
1.26.0 or older, because newer versions change the scores.
Links
MIT
Metadata
Release files for tokz 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tokz-0.6.1.tar.gz | 101.2 kB | Without provenance | Details for tokz-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokz-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for tokz-0.6.1-py3-none-any.whl |
Total release size: 117.4 kB
Release files / tokz-0.6.1.tar.gz
| Download URL | tokz-0.6.1.tar.gz |
|---|---|
| Size | 101.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4571f433fb64d446b294fb4aff9d6baf725d9831901d8ce1668a083deeac0476
|
|
BLAKE2b-256 checksum How to use checksums |
62c8abbd528a6f40e967cf85ed5dd85d02e1a826dff61c78952961a45a1f98fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / tokz-0.6.1-py3-none-any.whl
| Download URL | tokz-0.6.1-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33d8466ee321c087303dcbe96f8d2fe6118df85c8ffb86464f20d6e55f284767
|
|
BLAKE2b-256 checksum How to use checksums |
253675fee6c0cb0d332de60f34bb0ec419ed236e3f5c7de49e5f89c472300083
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for tokz 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.