choose
choose picks the one choice from your list that best fits a piece of text, and prints it. When even the best choice falls short of the bar, it says not sure (unsure).
echo 'Please refund my order.' | thinkthen choose \ --choice billing --choice shipping --choice other \ 'What is the message about?'Output
billing
billing: the message asks for money back.
Another choice
Section titled “Another choice”echo 'Where is my parcel?' | thinkthen choose \ --choice billing --choice shipping --choice other \ 'What is the message about?'Output
shipping
shipping: the message asks about a delivery.
Not sure
Section titled “Not sure”choose picks the choice with the highest chance. If that chance is below the bar, it says not sure. The bar is 0.5 unless you set --threshold.
echo 'I was charged twice and my parcel is late again.' | thinkthen choose --threshold 0.9 \ --choice billing --choice shipping --choice other \ 'What is the message about?'Output
unsure
Not sure: the message is about billing and shipping at once, so neither choice reaches 0.9. Send not sure to a person. Never send it to a default choice.
See why
Section titled “See why”See why
--json prints the details. This jq keeps the chance of each choice.
echo 'Please refund my order.' | thinkthen choose --json \ --choice billing --choice shipping --choice other \ 'What is the message about?' | jq -c '.detail.labels'Output
{"billing":0.98,"other":0.02,"shipping":0.0}
billing has 0.98, well above the bar of 0.5, so choose picks it. JSON output lists every field.
Move the bar
Section titled “Move the bar”Move the bar
Raise the bar to 0.99 and the same clear message is not sure, because billing has 0.98.
echo 'Please refund my order.' | thinkthen choose --threshold 0.99 \ --choice billing --choice shipping --choice other \ 'What is the message about?'Output
unsure
Lower the bar to accept a closer call. Raise it to answer only when one choice clearly wins.
Use the answer in a script
Section titled “Use the answer in a script”Use the answer in a script
--check turns the answer into the exit code, and the choice still prints.
message='Please refund my order.'if topic=$(echo "$message" | thinkthen choose --check \ --choice billing --choice shipping \ --choice other 'What is the message about?')then echo "send to the $topic queue"else status=$? case "$status" in 1|3) echo 'send to a person' ;; *) exit "$status" ;; esacfiOutput
send to the billing queue
| Answer | Exit code with --check |
|---|---|
| a choice | 0 |
unsure |
3 |
Without --check, choose exits 0 whenever it answers. Exit codes lists every code.
Choose for every row of a CSV file
Section titled “Choose for every row of a CSV file”Choose for every row of a CSV file
id,texta1,Please refund my order.a2,Where is my parcel?a3,I was charged twice for one invoice.thinkthen choose 'What is the message about?' \ --choice billing --choice shipping --choice other \ --from csv --column text --into topic < messages.csvOutput
id,text,topic
a1,Please refund my order.,billing
a2,Where is my parcel?,shipping
a3,I was charged twice for one invoice.,billing
--column names the column to read, and --into names the new answer column. A row that is not sure gets an empty cell. File types covers TSV, Excel and other files.
Options
Section titled “Options”Options
With --low and --high, choose answers only at or above the high bar. The low bar changes nothing, because choose never says no.
| Option | What it does |
|---|---|
<QUESTION> | Question to ask |
[FILE]... | Input files; default: standard input |
--name <NAME> | Optional execution identity |
--text <TEXT> | Judge this text instead of reading input |
--threshold <THRESHOLD> | Required probability |
--low <LOW> | Low probability bar |
--high <HIGH> | High probability bar |
--check [=<CHECK>] | Return the verdict as an exit code |
--choice <CHOICE> | Choice; repeat in order |
--describe <LABEL=TEXT> | Description for a label; repeat |
--column <COLUMN> | Field column; repeat; replaces a saved pointer |
--details [=<DETAILS>] | Add status, probability, error, detail and source columns |
--in-place [=<IN-PLACE>] | Replace source with backup |
--into <INTO> | Answer field for JSON Lines; column for tables |
--output <OUTPUT> | Destination path |
--sheet <SHEET> | Worksheet |
If choose can't answer a text, it prints an error and exits with code 2, 4, 5 or 6. Troubleshooting lists each error and its fix.
In code: Python · TypeScript · Go · Java · Kotlin · C# · R · Ruby · Rust · Swift · Zig · C · C++ · DuckDB · SQLite · PostgreSQL
Next: filter keeps only the lines that answer yes.