Skip to content
aoughwlPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jev

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.

What it is

Two things in one repo:

  1. A library (import jev): typed questions and answers over POST https://api.typesafe.ai/v1/systemone. JSON with jsonref, HTTP with the requests aowl port, error as value throughout (nothing raises).

  2. 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 one error: ... line on stderr. Neither the key nor any request header is ever printed.

The API, as found (2026-11-26)

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 the Authorization header (the bearer-token scheme), JSON {"model", "state", "questions": {NAME: QUESTION, ...}}. state is a string, an object or an array. GET /v1/models lists the models: jev-latest and jev-preview, both jev-1.14.0 today (the reply's model says which answered).
  • Question types (type): choice (criteria = {option: description}, 1 to 255 options; answer: choice, probabilities per option, confidence), score (criteria = a list of 1 to 10 ordered levels; answer: expected score, probabilities keyed "0", "1", ..., confidence, legend), noul (yes/no, optional criteria {true, false}; answer: noul = probability of yes), and box (a box in an image; needs the TypeSafe-Danger-Zone-Images: true header; 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: detail is 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.

Library API

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

./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.aowl

build.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

  • 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 with JEV_LIVE=1 and a key set; asks the ticket request and expects billing and a question. JEV_RECORD=PATH also writes the reply body to PATH (that is how choice-ok.json was recorded).

Config

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)

Toolchain notes

  • std/monotimes does not build alone with aowlmony (undeclared Timespec); the CLI reads the clock with std/posix/posix's clock_gettime directly.

Licence

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages