jev-bridge
Turn any generic OpenAI-compatible inference service into a Jev-style decision scoring service, in a single 7 MB binary with no Python dependency.
What it does
Jev-style decisions are not a model format; they are a readout. This bridge
implements the direct-options-v1
contract on top of any runtime that can return next-token log probabilities:
- render a fixed decision prompt through the serving runtime's own chat
template (system instruction plus a
{"evidence", "criterion", "options"}JSON payload, thinking disabled); - take the final position of one forward pass;
- softmax only over the 2–16 fixed uppercase answer letters
A–P; - return a typed System One result without generating any answer text.
The upstream model, its weights and its quantization stay exactly where they are. This process copies no weights and modifies no model.
What it does not do
- It is not a reimplementation of Jev and does not impersonate it:
--served-modelrefuses names starting withjev. - Returned probabilities are conditional scores over the supplied options
with
calibrated=False. They are not operational confidence. - It performs no calibration and recommends no thresholds. Validate on your own workload before automating anything consequential.
Supported types
Question types (POST /v1/systemone)
| Type | Shape | Returns |
|---|---|---|
choice |
criteria object with 2–16 options |
winning option id, full distribution, confidence |
noul |
optional criteria with true / false |
probability assigned to true |
score |
ordered criteria array of 2–10 levels |
probability-weighted value, legend, confidence |
instructions is optional for all three; a type-specific generic question is
substituted when it is omitted. Criteria values may be strings, objects, arrays
or null; structured values are rendered as JSON.
Upstream runtimes
| Runtime | Status | How it is reached |
|---|---|---|
llama.cpp (llama-server) |
fully supported | /apply-template + /tokenize for the contract, /v1/completions or /completion for scoring |
| Generic OpenAI-compatible | supported when the runtime exposes logprobs | /v1/completions with logprobs |
| vLLM | supported; supply the template | allowed_token_ids + logprob_token_ids, or allowed_token_ids + top-k; render with --chat-template-file |
The bridge picks one of these transports at startup by probing, and refuses to start rather than guessing. See Transport probing.
Quality alignment
144 authored decisions from fastjev, scored row by row. The reference is the
committed BF16 Torch run; this bridge ran llama.cpp Q8_0 over the same
fixture with the same metric definition (mean_family_balanced_accuracy).
| Metric | Reference (BF16 Torch) | Bridge (llama.cpp Q8_0) |
|---|---|---|
prompt_sha256 equal |
— | 144 / 144 |
input_tokens equal |
— | 144 / 144 |
mean_family_balanced_accuracy |
0.6863 | 0.6810 |
global_balanced_accuracy |
0.6998 | 0.6930 |
| argmax agreement | — | 139 / 144 (96.5%) |
prompt_sha256 and input_tokens match on every one of the 144 rows. That
is the strongest available evidence that the bridge renders the prompt
byte-identically to the reference implementation and tokenizes identically.
The 0.0053 quality delta is therefore attributable to Q8_0 quantization, not to
the bridge.
All five argmax disagreements fall on rows where the top two options are close
(top-2 margins between 0.01 and 0.24). The bridge flips two rows in the right
direction and three in the wrong one, which matches the observed net delta.
Per family, candidate_selection and rule_application are identical and only
evidence_interpretation moves (0.7675 → 0.7516).
Row-level evidence:
- results/alignment-minicpm5-2b-authored144.json
- results/bridge-minicpm5-2b-q8-authored144.predictions.jsonl
Quick start
Build tip: if the crates.io index is slow on your network, configure a mirror in a local
.cargo/config.toml. That file is gitignored.
Probe only, without serving:
The probe prints the chosen transport, its endpoint, and the sixteen answer-slot token ids it resolved.
Batch scoring
--score reads fastjev-format rows and writes JSONL predictions, which is what
the alignment run above used:
Input rows are {"id", "state", "question", "options": [{"id", "description"}]};
extra fields are ignored. Output rows carry probabilities, option_logprobs,
input_tokens, prompt_sha256 and prompt_version. The output path must not
already exist.
This path bypasses the System One criteria rendering (which prefixes each
option description with id: ), so it matches the reference prompt contract
exactly — that is why the alignment check can compare prompt hashes byte for
byte.
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/systemone |
System One compatible scoring for choice, noul and score |
| GET | /v1/models |
Configured model metadata |
| GET | /health |
Chosen transport, endpoint, answer-slot ids, template kwargs |
GET /health is the first place to look when something is off: it states what
the bridge actually negotiated instead of leaving you to guess.
Using it as a library
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
= { = "0.12", = ["json"] }
= "1"
use ;
use ;
async
Serve the same bridge over HTTP with jev_bridge::server::router:
use Arc;
use ;
let state = new;
let listener = bind.await?;
serve.await?;
Public modules:
| Module | Contents |
|---|---|
server |
Bridge, BridgeConfig, DetailedScore, router, AppState |
strategy |
Probe, typed request bodies, CompletionResponse, parsing |
prompt |
prompt contract, ChatMessage, RuntimeClient, LocalComponents, ChatTemplate |
render |
LocalRenderer — minijinja rendering with CPython string methods |
tokenizer |
LocalTokenizer — the tokenizers crate behind the same checks |
wire |
SystemOneResponse, Answer, request validation, OrderedMap |
Bodies, responses and answers are typed structs rather than loose JSON
documents: the scoring request/response pairs, the System One response with its
choice/noul/score enum, and the health payload are all Serialize/
Deserialize types. serde_json::Value remains only where the payload really
is dynamic — the caller's state, the values inside criteria, and the Python
JSON layout that the prompt contract pins byte for byte.
Running without runtime endpoints
Runtimes differ in which helper endpoints they expose. The bridge uses the runtime for both rendering and tokenization by default, and each half can be moved in-process independently:
| Flag | Replaces | Needed for |
|---|---|---|
--chat-template-file + --chat-template-context |
/apply-template |
vLLM and anything else without that endpoint |
--tokenizer-json |
/tokenize and /detokenize |
runtimes with no tokenize endpoint, or fully offline startup |
# Render locally, tokenize through the runtime
# Both halves local: no /apply-template and no /tokenize needed
Take the model's own template and tokenizer, never a hand-written or
foreign pair: a different vocabulary silently scores the wrong token ids, and a
different template silently changes the prompt. For a llama.cpp server both can
be read from /props:
|
The template context carries the variables transformers supplies besides the
messages. A template that begins with {{- bos_token }} needs bos_token
there, or the rendered prompt silently lacks its BOS token.
GET /health reports renders_locally and tokenizes_locally, so you can
confirm what the bridge actually negotiated.
Templates written for transformers use Python string methods (split,
replace, startswith, strip, …) that the Rust minijinja lacks. The bridge
supplies them with CPython semantics, including treating the argument of
strip/lstrip/rstrip as a character set rather than a prefix. Local
rendering was checked byte for byte against llama.cpp's own /apply-template
output on a real model template.
Examples
Three runnable examples live in examples/. Each reads its configuration from
the environment, so no credentials are baked in:
| Example | Shows |
|---|---|
cargo run --example score_rows |
connecting a Bridge, scoring rows, reading DetailedScore |
cargo run --example serve |
exposing the same bridge over HTTP with router |
cargo run --example local_template |
rendering a template in-process and inspecting the prompt |
# only if the server requires it
Transport probing
At startup the bridge tries each transport below with a real sixteen-option probe request and adopts the first one that works:
| Name | Endpoint | Fields relied on | Typical runtime |
|---|---|---|---|
vllm-logprob-token-ids |
/v1/completions |
allowed_token_ids + logprob_token_ids |
vLLM |
vllm-allowed-token-ids-top-k |
/v1/completions |
allowed_token_ids + top-k |
vLLM (fallback) |
openai-completions-top-k |
/v1/completions |
top-k | generic OpenAI-compatible, llama.cpp |
llamacpp-native-n-probs |
/completion |
n_probs |
llama.cpp native |
The two vLLM transports claim the distribution is restricted to the option
tokens. If a server ignores those fields and returns foreign tokens, the
transport is rejected rather than silently adopted — otherwise /health
would report a contract the service is not actually honouring.
Unrestricted distributions need a generous top-k: on a 2B quantized model,
k=20 missed four of the sixteen answer letters and k=50 covered all of
them. Unrestricted transports therefore request 4 × options (floor 32, cap
128). A missing option is always an error, never a zero.
Startup contracts
Two checks run before serving; failing either exits instead of scoring wrong numbers:
- Single-token contract — each of
A–Pmust be exactly one token, and/detokenizemust return them asABCDEFGHIJKLMNOP. - Boundary contract — appending a letter to the rendered prompt must
produce exactly
prompt tokens + [that letter's token]. Otherwise the prompt's last token merges with the letter and the scored logit belongs to a different token than the chosen option.
CLI reference
| Flag | Description |
|---|---|
--base-url |
Upstream OpenAI-compatible root, e.g. http://127.0.0.1:8080/v1 |
--native-base-url |
Native root for llama.cpp /completion; defaults to --base-url without /v1 |
--model |
Model name sent upstream |
--upstream-key |
Upstream bearer token; prefer JEV_BRIDGE_UPSTREAM_KEY |
--served-model |
Model id this bridge accepts; defaults to --model; must not start with jev |
--served-model-description |
Description returned by GET /v1/models |
--served-model-release-date |
ISO date returned by GET /v1/models (required) |
--chat-template-kwargs |
JSON passed when rendering the template; default {"enable_thinking": false} |
--chat-template-file |
Render the template locally from this Jinja file instead of calling /apply-template |
--chat-template-context |
JSON added to every local render, e.g. {"bos_token": "<s>"} |
--tokenizer-json |
Tokenize locally with this tokenizer.json instead of calling /tokenize |
--max-input-tokens |
Reject rows above this token count (no truncation) |
--host / --port |
Bind address, default 127.0.0.1:8100 |
--api-key |
Bearer token clients must present; prefer JEV_BRIDGE_API_KEY |
--probe-only |
Probe, print the result, exit |
--score / --input / --output |
Batch scoring mode |
Credentials are read from environment variables or the command line and are never written to disk.
Alignment with fastjev
- The payload uses Python's
json.dumps(..., ensure_ascii=False)separator layout (,and:); a unit test pins this against real CPython output, and the alignment run confirms it with 144 matching prompt hashes. - Softmax matches fastjev's helper (subtract the maximum first).
fastjev.confidence_methodisone-minus-normalized-entropy, matching fastjev's System One adapter; it is not TypeSafe's private statistic.- Template rendering is delegated to the serving runtime (
/apply-template), so the prompt is exactly what that runtime feeds the model. This is also why the chat completions endpoint must not be used: there the prompt is decided by the server's template and cannot be guaranteed to match this contract.
Testing
52 tests: 37 unit tests (wire contract, CPython JSON layout, the three response
shapes, softmax stability, missing options must error, CPython-semantics
template methods) plus 15 integration tests split between tests/bridge.rs
(library API, including DetailedScore fields) and tests/contract.rs (HTTP
surface, local rendering, local tokenization).
Known limitations
- Decisions are serialized: several questions in one request are scored one after another, and upstream calls are not batched.
- The upstream revision cannot be pinned by this process. Reproducibility depends on the upstream's own version management.
- The alignment reference is BF16 while the bridge run is Q8_0, so the 0.0053 delta is a quantization delta, not a bridge delta. An equal-precision comparison needs a BF16 upstream.
- With a local tokenizer the bridge trusts the file it is given. A foreign
tokenizer.jsonproduces plausible-looking scores from the wrong token ids, soverify_special_tokenschecks the context's special tokens against the vocabulary at startup but cannot check that the vocabulary is the model's own.