cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

main
012 / docs / formulas / jev.md
jev.md 5.1K rendered
1---2title: "JEV functions"3sidebar_position: 74---56# JEV functions78![JEV functions classifying reviews, answers arriving in the background](../media/jev.gif)910With a TypeSafe API key, four functions ask the hosted JEV model about a11value (a cell, a range or text). They follow Sheets' argument style: the12value, the question, then what the answers mean.1314| Function | Returns | Like |15|---|---|---|16| `=JEV.TEST(A2, "Is this a complaint?", [yes means], [no means])` | TRUE or FALSE | an `IF` condition, a boolean mask |17| `=JEV.PROB(A2, "Is this a complaint?")` | probability of yes, as a percent | `predict_proba` |18| `=JEV.CLASSIFY(A2, "Sentiment", "negative, positive", [descriptions])` | the best label | `SWITCH`, `pd.cut` |19| `=JEV.SCORE(A2, "Urgency", "low, mid, high")` | a score from 0 to levels-1 | a rating scale |2021Labels, descriptions and levels can also be ranges. Answers arrive in the22background (cells show `Loading…`), are cached by question, and the context23line shows the confidence for the selected cell. Data > Ask JEV again24re-asks the selection.2526Without a key the functions show `#N/A` and say how to add one.2728## Setup2930The API key never goes in a file 012 reads or on a command line. Store it31once in your operating system's credential store:3233```sh34012 config set-key # asks for the key without echoing it35op read op://Private/TypeSafe/credential | 012 config set-key # or pipe it in36012 config delete-key # remove it37```3839or in the app, File > Settings > JEV API key, which asks on the context40line with the key masked and turns JEV on at once. It then checks the key41with one test call, a fixed yes/no question about `2 + 2 = 4` that sends42none of your data, and says "Key saved and checked" or "Key saved, but the43check failed" with the reason (such as the service refusing the key). A44key whose check failed is kept, since a check can fail because the45service can't be reached, not the key; store the right one the same way. `012 config` says where the46key would come from, without showing it.4748012 looks for the key in this order:49501. **`TYPESAFE_API_KEY`** in the environment, for CI, containers and51 one-off runs.522. **The credential store**: the macOS Keychain, the Windows Credential53 Manager, or the Secret Service on Linux and the BSDs (GNOME Keyring,54 KWallet, KeePassXC; this needs `secret-tool`, in the `libsecret-tools`55 package on Debian and Ubuntu). The item is service `012`, account56 `jev-api-key`. `jev-credential-store = false` in the config skips it.573. **`jev-api-key-command`** in the config: a command that prints the key,58 for password managers:5960 ```61 jev-api-key-command = op read op://Private/TypeSafe/credential62 jev-api-key-command = pass show typesafe63 jev-api-key-command = sh -c 'gpg -dq ~/.secrets/typesafe.gpg | head -1'64 ```6566 It runs the first time a sheet asks JEV something, not at every67 start, for at most 10 seconds, and the first line it prints is the key.68 It runs without a shell: the value is split into words, with quotes69 grouping words and a backslash escaping the next character, and70 nothing is expanded (`$HOME`, `~`, `*`, pipes and `;` are passed on71 literally). For a pipeline, write `sh -c '...'` yourself.7273The service's address and model come from the config file or the74environment only: `jev-base-url` (or `TYPESAFE_BASE_URL`), which must be75https unless it's this machine, and `jev-model` (or76`TYPESAFE_DEFAULT_MODEL`). See [Configuration](../reference/config.md).7778**012 doesn't read `.env` files.** A `.env` next to a downloaded sheet79could set `TYPESAFE_BASE_URL` and send your key to someone else's server.80If the directory 012 starts in has a `.env` with `TYPESAFE_API_KEY`, the81context line suggests `012 config set-key`; 012 never reads the key from82it.8384## How requests behave8586A JEV cell's question goes to the answer cache first, and to the service87only when it's new:8889```mermaid90sequenceDiagram91 participant Cell as a JEV cell92 participant Cache as the answer cache93 participant JEV as the JEV service94 Cell->>Cache: the question: value, question and criteria95 alt asked before96 Cache-->>Cell: the answer97 else new98 Cache-->>Cell: Loading…99 Cache->>JEV: in the background, eight at a time100 JEV-->>Cache: the answer, or why it failed101 Cache-->>Cell: recalculated with it, or #35;ERROR!102 end103```104105- The status line counts requests in flight, and terminals that support106 it (OSC 9;4) show progress in the tab.107- Answers are cached by the exact question, so recalculating, undo and108 redo never ask twice, and `JEV.TEST` and `JEV.PROB` on the same109 question share one request.110- Errors in the inputs (`#DIV/0!` in the value, an empty question, fewer111 than two labels, more than the service's 255 labels or 10 score levels)112 show as errors at once and are never sent.113- A failed request shows `#ERROR!`, and the context line says why.114- 012 never logs, shows or saves the API key anywhere but the credential115 store, and never passes it as a command-line argument: the macOS116 Keychain and the Secret Service get it on stdin.117118The client is [typesafe-go](https://github.com/FelineStateMachine/typesafe-go).