An aowl client (the Nimony language, built with aowlmony) for TypeSafe's System One API
(the model Jev), plus a small headless CLI (jev -q "…" --option A --option B).
Part of the aoughwl stack. Its siblings are
aoughwl/openai and
aoughwl/anthropic: those ask a model to
write; this one asks a model to choose. Jev takes a piece of text (the state) and
closed questions about it, and answers each with a probability distribution, in about
a quarter of a second. Code can act on a confident answer and send a doubtful one to a
slower model or a person.
Two things in one repo:
-
A library (
import jev): typed questions and answers overPOST https://api.typesafe.ai/v1/systemone. JSON withjsonref, HTTP with therequestsaowl port, error as value throughout (nothing raises). -
A CLI (
bin/jev): one question, the distribution printed:$ jev -q "Which greeting is this?" --option hello --option goodbye --state "hi there!" --time hello 1.000 #################### goodbye 0.000 choice: hello confidence: 1.000 model: jev-1.14.0 tokens: 291 in time: 250 ms $ jev -q "What kind of support ticket is this?" \ --option "billing=charges, invoices, refunds" \ --option "bug=something in the product is broken" \ --option "feature=a request for something new" \ --state "I was charged twice for my subscription this month." $ jev -q "Is this message a question?" --yes-no --state "Does the app work offline?" yes 0.980 #################### no 0.020 $ echo "The checkout page is down for every customer." | jev -q "How urgent is this ticket?" --score --option 1 --option 2 --option 3 --option 4 --option 5 --state - 1 0.010 2 0.000 3 0.000 4 0.010 5 0.980 #################### score: 3.960 confidence: 0.960 model: jev-1.14.0 tokens: 317 in $ jev -q "Which?" --option a --option b --state x --json # the reply body as sent
A score is the expected level counted from 0 (3.96 here is "5" on a 1 to 5 scale).
Exit 0 with an answer; 2 with no
TYPESAFE_API_KEY(no network); 3 when the API refused the request (4xx, or a reply that does not fit the question); 4 when it is down (5xx, 429, transport). Errors are oneerror: ...line on stderr. Neither the key nor any request header is ever printed.
From the public docs (docs.typesafe.ai, its llms.txt and api.typesafe.ai/openapi.json,
API version 0.2.0) and live calls:
POST /v1/systemone, the key in theAuthorizationheader (the bearer-token scheme), JSON{"model", "state", "questions": {NAME: QUESTION, ...}}.stateis a string, an object or an array.GET /v1/modelslists the models:jev-latestandjev-preview, bothjev-1.14.0today (the reply'smodelsays which answered).- Question types (
type):choice(criteria={option: description}, 1 to 255 options; answer:choice,probabilitiesper option,confidence),score(criteria= a list of 1 to 10 ordered levels; answer: expectedscore,probabilitieskeyed "0", "1", ...,confidence,legend),noul(yes/no, optionalcriteria{true, false}; answer:noul= probability of yes), andbox(a box in an image; needs theTypeSafe-Danger-Zone-Images: trueheader; not wrapped here). - Several questions per request: any number, each answered independently against
the same state, in parallel; the only limit is context (64k tokens per request, 32k
for the state plus one question; 262k with
TypeSafe-Danger-Zone-Long-Context: true). There is no separate batch endpoint: a batch is one request with many questions. - Confidence is not the top probability: for a choice with n options it is
(p_max - 1/n) / (1 - 1/n). The docs suggest the top-to-second ratio to see a close runner-up. - Errors: 400 (a request rule, or
max_tokens_exceeded), 401 (key), 413 (body over 32 MiB), 415 (compression), 422 (validation:detailis a list of{loc, msg}), 429 (rate limit, per organisation, tokens and requests per second), 529 (overloaded). The library reads 4xx except 429 as refused and 429/5xx/transport as down. - Price: input tokens only, $0.042 per million (output free). A one-question request about a sentence is about 280 to 320 input tokens.
- Latency measured here (Linux, a fresh TLS connection per call, 7 calls): 212 to 353 ms per request, median about 240 ms.
import jev
let c = newJev() # TYPESAFE_API_KEY, TYPESAFE_URL, JEV_MODEL from env
let r = c.ask("I was charged twice for my subscription this month. Can you refund one?",
@[choice("kind", "What kind of support ticket is this?",
@[opt("billing", "charges, invoices, refunds"),
opt("bug", "something in the product is broken"),
opt("feature", "a request for something new")]),
noul("question", "Is this message a question?"),
score("urgency", "How urgent is this ticket?",
@["1 - can wait", "2 - this month", "3 - this week", "4 - today", "5 - right now"])])
if r.ok:
let a = r.answer("kind")
echo a.choice, " ", a.confidence # billing 1.0
for p in a.probabilities: echo p.name, " ", p.p
echo r.answer("question").noul # 0.79
echo r.answer("urgency").score + 1 # about 3 of 5
else:
echo r.error, (if r.refused: " (fix the request)" elif r.down: " (try later)" else: "")| type | what it is |
|---|---|
Jev |
the client: key, url, model, timeout |
Question |
choice(...), noul(...), score(...): a name, the instructions, the options |
Option |
opt(name, description): one choice option |
Reply |
ok, error, status, refused, down, model, answers, tokens, raw |
Answer |
choice, probabilities (in the question's order), confidence, noul, score |
A reply is checked before it is believed. parseReply refuses (ok = false,
refused = true) an answer that is missing, of the wrong type, whose probabilities lack an
option, name one that was not asked, fall outside 0..1 or do not sum to 1 (within 0.02),
or whose choice is not an option. parseReply(status, body, questions) needs no
network, so recorded replies can be replayed (the tests do). buildBody gives the exact
request body, for hashing a request into a recording key. checkQuestions says why a
question cannot be sent (no options, two with one name, ...) without sending it.
./build.sh # bin/jev
./build.sh test # + the offline tests (tests/tjev.aowl, on tests/replies/) and the live one
./build.sh example # + bin/ask from examples/ask.aowlbuild.sh finds jsonref,
requests, zlib, and requests' native backend
(tcp, net, tls) as sibling checkouts under $DEV (default ~/Desktop/dev), or by
$JSONREF, $AOWL_REQUESTS, $ZLIB, $AOUGHWL_GIT. This repo's sources are .aowl;
some deps still ship .nim, and aowlmony build renames .nim files to .aowl in
place, so build.sh copies everything into build/ before building. HTTP uses requests' native TLS backend; curl-impersonate is compiled out
(-d:requestsNoCurl).
tests/ticket.aowl: the example request both tests share, a support ticket asked three questions at once (kind: billing / bug / feature,question: yes/no,urgency: a 1 to 5 score).tests/tjev.aowl, offline: the request body byte for byte, the question checks, real recorded replies (choice-ok.json: the live test's reply to the ticket request; a 401; a 422; the docs' score example) and planted, hand-written bad ones (an option without a probability, a sum of 1.8, no probabilities, an unknown key), each refused with its reason, and controls (the real good reply read against a question with a fourth option, or a score with a sixth level, is refused). 36 checks.tests/tlive.aowl, the one live test: runs only withJEV_LIVE=1and a key set; asks the ticket request and expectsbillingand a question.JEV_RECORD=PATHalso writes the reply body to PATH (that is howchoice-ok.jsonwas recorded).
| env | meaning |
|---|---|
TYPESAFE_API_KEY |
credential (required unless passed to newJev) |
TYPESAFE_URL |
the endpoint (default https://api.typesafe.ai/v1/systemone) |
JEV_MODEL |
the model (default jev-latest) |
std/monotimesdoes not build alone with aowlmony (undeclaredTimespec); the CLI reads the clock withstd/posix/posix'sclock_gettimedirectly.
MIT — see LICENSE.