-
Notifications
You must be signed in to change notification settings - Fork 130
python client for local llm decisions
A good Python client for a local decision server is about twenty lines: one requests.Session
reused for every call, an explicit timeout, retries only for connection failures, and a helper
that returns the noul of each question as a float. The server is jev serve on
127.0.0.1:8017, the call is POST /v1/systemone, and the helper asks only noul questions,
whose answer is the probability that the answer is yes. Everything else in the client is about
failing loudly: a 422 means the request itself is wrong and must not be retried, a 401 means the key is
missing.
The README's four-line example is enough to try the model. It is not what you want in a service
that makes thousands of calls, because requests has no timeout by default and opens a new
connection per call unless you use a session. Both are cheap to fix, and on a server that
answers in 25 to 110 ms on a laptop CPU the connection setup is not a rounding error.
This page is the helper, the three settings that matter (session, timeout, retries), how to read the errors the server returns, and what the server does when several threads call it at once. The snippets are minimal sketches to adapt, not a published library; they use only the documented API.
import os
import requests
URL = os.environ.get("JEV_URL", "http://127.0.0.1:8017")
session = requests.Session()
if os.environ.get("JEV_API_KEY"):
session.headers["Authorization"] = f"Bearer {os.environ['JEV_API_KEY']}"
def decide(state, questions, timeout=(3.05, 10)):
"""state: a string or a JSON-able dict/list. questions: {name: question text}."""
body = {
"model": "jev-latest",
"state": state,
"questions": {k: {"type": "noul", "instructions": q} for k, q in questions.items()},
}
r = session.post(f"{URL}/v1/systemone", json=body, timeout=timeout)
if r.status_code == 422:
raise ValueError(r.json()["detail"])
r.raise_for_status()
return {k: a["noul"] for k, a in r.json()["answers"].items()}Called as decide("I was charged twice for the same order.", {"billing": "Is this a billing problem?"}), this is the README's Quickstart request, for which the README shows 0.94. The
helper keeps the question names you chose, so the result is a plain dict of floats you can
threshold. Ask every question you have about one text in one call: the text is read once and
the extra questions cost a fraction of the first (three questions about 66 ms against 49 ms
for one, on the reference laptop).
The requests documentation is direct on both. A Session "will use urllib3's connection
pooling. So if you're making several requests to the same host, the underlying TCP connection
will be reused". And on timeouts: "By default, requests do not time out unless a timeout value
is set explicitly. Without a timeout, your code may hang for minutes or more."
A tuple sets the two timeouts separately: the connect timeout (the docs suggest a value slightly larger than a multiple of 3) and the read timeout, which is the wait for the server's reply. Size the read timeout from your own traffic, not from the laptop figures. Two things make a reply slower than one inference:
- Long texts. On the reference CPU a 191-token text read from scratch took 112 ms against 26 ms for a 30-token one; how that adds up is on why latency grows with the length of the text.
- Queueing. Concurrent requests share one CPU. Small requests arriving together are read in one model call, but throughput barely grows with the number of clients: on the reference laptop, 1 client got 8.7 requests/s (median 110 ms), 4 clients 9.8/s (390 ms) and 8 clients 10.1/s (780 ms). Ten threads calling at once do not get ten answers in the time of one; most of them wait. A thread pool in the client raises throughput only up to the point where the server is busy all the time. The difference between the two numbers is the subject of throughput vs latency for a decision server.
Requests itself "does not retry failed connections", and the documented way to add retries is a
urllib3.util.Retry mounted on the session through an HTTPAdapter. One detail matters for
this API: urllib3 by default retries only methods "considered to be idempotent", and POST is not
among them, so you must opt in:
from requests.adapters import HTTPAdapter
from urllib3.util import Retry
retries = Retry(total=3, backoff_factor=0.1,
status_forcelist=[502, 503, 504], allowed_methods={"POST"})
session.mount("http://", HTTPAdapter(max_retries=retries))Retrying a decision is safe in the sense that matters: beyond a cache of recent texts that only
makes them faster to read, the server stores nothing about a request, so sending it twice
changes no answer. What you should not retry is a 4xx. The
status_forcelist above covers the gateway errors a reverse proxy in front of the server might
return; the server's own 422 and 401 are left alone, because the same request will fail the
same way.
The server answers a request it cannot handle with 422 and a body of the form
{"detail": [{"loc": [...], "msg": "...", "type": "..."}]}, the same shape FastAPI uses for
its own validation errors. From the code, the usual causes are:
- a
choicewith one option or ascorewith one level; - a
modelthat is neither ajev-*alias nor the served model's name; - an unknown field, for example a misspelt
instructions: requests reject fields they do not know, so a typo fails loudly instead of being ignored; - an empty
state, astateover 256 KB, or a question whose prompt, the state plus that question, is longer than the context limit (8,192 tokens by default).
loc points at the offending field, which is why the helper raises it as it is. A 401
carries WWW-Authenticate: Bearer and appears only when the server was started with
JEV_API_KEY; setup is on securing a local LLM server with an API key.
jev serve loads the model before it starts listening, so while it loads, the port refuses
connections, and once it answers, GET /health returns {"status": "ready", ...}. /health
needs no key. A worker that starts together with the server can poll it with a short timeout
and a sleep between attempts, and begin sending decisions only after the first ready. What the
same endpoint reports about the loaded model is worth logging next to every decision; logging LLM decisions for audit covers
what else to keep.
The helper does nothing about the model's own weaknesses. It returns a probability, and what that probability is worth depends on the question: on our 999-question test it was right 0.954 of the time on facts stated in the text and 0.584 on arithmetic. A threshold of 0.5 is the neutral starting point; how to choose a threshold for P(yes) is the next step. The model reads English only.
Is there an official Python SDK for jevos? No separate one. The server speaks TypeSafe's
Jev wire format, so code written for Jev's SDK works unchanged for yes/no, choice and score questions; otherwise a
plain requests call is all it takes.
Should I use async? Only if your application is already async. Concurrent requests share one CPU (8 clients got 10.1 requests/s against 8.7 for one), so concurrency on the client side barely makes one server faster.
What timeout should I set? A connect timeout of a few seconds and a read timeout sized from your longest texts and your peak concurrency, measured on your machine.
Why do I get 422 on a question that looks fine? Check loc in the body: a misspelt field,
a choice with one option, or a model name that is not jev-* are the common causes.
Can I send a dict as the state? Yes. state accepts a string, an object or an array.
See also: ask a local LLM a yes/no question, calling a local LLM decision server from JavaScript and curl examples for a local LLM decision API.
- Endpoints, status codes, error shape, the 256 KB state limit and the default context: read from the source of jev.
- Latencies, the several-client throughput and the billing example: the
jev README and our measurements (Intel Core Ultra 7 255H,
16 threads). Accuracy by kind: our 999-question test set,
jevos-q4_k_m. - Sessions, timeouts and the retry example: Requests, Advanced Usage, fetched 2026-09-29.
- Default retried methods: urllib3
Retry, fetched 2026-09-29.
From the notes of jev, a yes/no decision model that runs on a laptop CPU. The helper is short on purpose: the server has one endpoint and one answer shape per question type.
- Ask a local LLM a yes/no question and get P(yes)
- Zero-shot text classification with yes/no questions
- LLM policy decisions: put the rule in the question
- LLM as a judge on a CPU
- Why a small LLM says yes when the answer is no
- Small LLMs and arithmetic in yes/no questions
- Our held-out benchmark said 0.855, new questions said 0.757
- jevos vs Jev vs Laya for yes/no decisions
- An open-source alternative to Jev for yes/no decisions
- jevos vs the OpenAI API for yes/no classification
- jevos vs Ollama for yes/no decisions
- jevos vs bart-large-mnli for zero-shot classification
- A yes/no LLM vs a fine-tuned BERT classifier
- jevos vs SetFit: zero-shot vs few-shot classification
- jevos vs Llama Guard for content safety checks
- jev serve vs llama.cpp server for classification
- jevos vs LM Studio: a decision server, not a chat app
- Local vs hosted LLM decisions: latency, cost, privacy
- A yes/no LLM vs a business rules engine
- LLM decisions vs keyword rules and regex
- The fastest AI model for yes/no decisions
- What makes a local LLM fast on a CPU
- Why one forward pass beats generating an answer
- Prefill vs decode: where LLM latency comes from
- Why LLM latency grows with the length of the text
- Why a hosted LLM API cannot answer in 50 ms
- Many questions about one text: why the extra ones are cheap
- CPU or GPU for a small LLM
- Latency budgets: where a 200 ms model fits
- Measuring LLM latency: median, p90 and warm-up
- Q4_K_M vs Q8_0: speed and size for a small model
- Throughput vs latency for a decision server
- What P(yes) means, and what it does not
- LLM calibration explained with yes/no answers
- Expected calibration error (ECE), explained
- Temperature scaling for LLM probabilities
- Platt scaling for a yes/no model
- Reading a reliability diagram
- How to choose a threshold for P(yes)
- Thresholds when a wrong yes costs more than a wrong no
- Human in the loop AI with a review band
- Precision and recall at a P(yes) threshold
- Base rates: why a 0.9 yes can still be wrong often
- Combining yes/no answers with AND, OR and NOT
- Logits, log-odds and P(yes)
- LLM confidence scores: probabilities vs self-reports
- How to write yes/no questions an LLM answers well
- Negation in yes/no questions for an LLM
- One condition per question: splitting compound questions
- Ask whether the text says it at all
- Scores as yes/no thresholds: is it at least high?
- Sending JSON as the text: designing the state
- Why wording changes an LLM's answer, and how to test it
- Mainly about: questions for messages with several topics
- Yes/no questions about tone and emotion
- Asking about intent: what does the writer want?
- Yes/no questions about long documents
- Using an English-only LLM with other languages
- Content moderation with a local LLM
- A Discord moderation bot with a local LLM
- Spam detection with yes/no questions
- Review moderation with a local LLM
- Email triage with a local LLM
- Support ticket routing with yes/no questions
- Urgency detection in customer messages
- Sentiment analysis with yes/no questions
- Intent detection with a local LLM
- Lead qualification with yes/no questions
- Fraud case triage with a local LLM
- Phishing email screening with a local LLM
- Log and alert triage with a local LLM
- Checking text for personal data with yes/no questions
- Prompt injection screening with a small model
- Document classification with a local LLM
- Product categorization with yes/no questions
- Contract clause detection with a local LLM
- Refund request triage with a local LLM
- Detecting cancellation intent in customer messages
- RAG evaluation with yes/no questions
- RAG faithfulness check with a local LLM
- Hallucination detection with a local LLM
- LLM regression tests in CI with yes/no checks
- Rubric design for an LLM judge
- Pairwise comparison with a yes/no judge
- LLM judge bias and how to control it
- Evaluation metrics for yes/no classifiers
- Building a yes/no test set for your own data
- Accuracy by kind of question: why one number hides failures
- Generating test questions with answers computed by code
- Benchmark contamination and truly held-out tests
- An LLM router with yes/no questions
- A model cascade: small model first, large model on doubt
- Semantic routing vs yes/no questions
- Gating AI agent tool calls with yes/no checks
- AI agent guardrails with yes/no questions
- Stop conditions for AI agents
- Logging LLM decisions for audit
- Reducing LLM cost with local yes/no decisions
- Replacing chat LLM calls with yes/no questions
- Structured output vs a probability
- A Python client for local LLM decisions
- Calling a local LLM decision server from JavaScript
- Local LLM yes/no decisions in n8n
- A Slack bot that uses local LLM decisions
- Home Assistant automations with local LLM decisions
- A LangChain tool for local yes/no decisions
- Batch decisions from files with jev decide
- Running LLM yes/no checks in GitHub Actions
- Securing a local LLM server with an API key
- curl examples for a local LLM decision API
- Self-hosted AI for decisions
- A private LLM for text classification
- On-premise LLM for business decisions
- GDPR and automated decision-making with an LLM
- Offline AI for decisions: no network needed
- Edge AI decisions on a CPU
- Run an LLM locally without a GPU
- Small language models explained
- When a small model is enough, and when it is not
- An LLM on a laptop: what it can do in real time
- What is GGUF, for someone deploying a classifier
- GGUF quantization types explained: Q4_K_M, Q8_0 and others
- GGUF vs safetensors
- llama.cpp vs Ollama for a classification service
- llama-cpp-python vs calling llama.cpp through ctypes
- llama.cpp on Windows without compiling
- Running llama.cpp CPU only
- Using llama.cpp prebuilt binaries instead of building