The Bash example opens this page.
choose: pick one option from your list.
question="Which team owns this?"
teams=(
--option "billing=Invoices, fees, and refunds."
--option "shipping=Parcels and delivery."
--option "account=Logins and passwords."
)
cat <<'EOF' |
Please refund the extra fee on my invoice.
My parcel went to the wrong address.
I cannot reset my password.
My parcel never came, and now I cannot log in to track it.
EOF
thinkthen choose "$question" "${teams[@]}" \
--batch 1 \
--lines \
--threshold 0.9 |
jq -r .valuebilling shipping account null
You give it one question, one piece of evidence, and 2 to 255 options. You get back one of your options, or null.
Read the answer
On one piece of evidence, a pick under the threshold or an exact tie at the top prints null and exits 3. In a stream, the run exits 0. choose never exits 1.
| Exit code | What it means |
|---|---|
| 0 | an option came back |
| 3 | not sure |
| 2 | usage or input error |
| 4 | the backend failed or refused, as it does for evidence over the size limit |
| 5 | a local failure |
| 70 | a defect in the tool |
Send the not-sure answers to a person.
Call it from your language
import thinkthen as tt
question = "Which team owns this?"
teams = {
"billing": "Invoices, fees, and refunds.",
"shipping": "Parcels and delivery.",
"account": "Logins and passwords.",
}
team_question = tt.question(
choose=question,
options=teams,
threshold=0.9,
)
texts = [
"Please refund the extra fee on my invoice.",
"My parcel went to the wrong address.",
"I cannot reset my password.",
(
"My parcel never came, and now "
"I cannot log in to track it."
),
]
owners = [
tt.choose(team_question, text).value
for text in texts
]
assert owners == ["billing", "shipping", "account", None]No Polars sample for choose.
No pandas sample for choose.
import assert from "node:assert/strict";
import * as tt from "thinkthen";
const question = "Which team owns this?";
const teams = {
billing: "Invoices, fees, and refunds.",
shipping: "Parcels and delivery.",
account: "Logins and passwords.",
};
const teamQuestion = {
choose: question,
options: teams,
threshold: 0.9,
};
const texts = [
"Please refund the extra fee on my invoice.",
"My parcel went to the wrong address.",
"I cannot reset my password.",
"My parcel never came, and now " +
"I cannot log in to track it.",
];
const owners = [];
for (const text of texts) {
owners.push((await tt.choose(teamQuestion, text)).value);
}
assert.deepEqual(owners, [
"billing",
"shipping",
"account",
null,
]);require "thinkthen"
question = "Which team owns this?"
teams = {
"billing" => "Invoices, fees, and refunds.",
"shipping" => "Parcels and delivery.",
"account" => "Logins and passwords."
}
team_question = ThinkThen.question(
choose: question,
options: teams,
threshold: 0.9
)
texts = [
"Please refund the extra fee on my invoice.",
"My parcel went to the wrong address.",
"I cannot reset my password.",
"My parcel never came, and now " \
"I cannot log in to track it."
]
owners = texts.map do |text|
ThinkThen.choose(team_question, text).value
end
raise unless owners == [
"billing",
"shipping",
"account",
nil
]No R sample for choose.
No Rust sample for choose.
#include <assert.h>
#include <stdio.h>
#include <json-c/json.h>
#include <thinkthen.h>
thinkthen_engine *tt = thinkthen_engine_new();
assert(tt);
const char *choose =
"{\"choose\": \"Which team owns this?\", "
"\"options\": {"
"\"billing\": \"Invoices, fees, and refunds.\", "
"\"shipping\": \"Parcels and delivery.\", "
"\"account\": \"Logins and passwords.\"}, "
"\"threshold\": 0.9, \"evidence\": \"%s\"}";
const char *texts[] = {
"Please refund the extra fee on my invoice.",
"My parcel went to the wrong address.",
"I cannot reset my password.",
"My parcel never came, and now "
"I cannot log in to track it.",
};
const char *teams[] = {
"\"billing\"",
"\"shipping\"",
"\"account\"",
"null",
};
char request[320];
for (int i = 0; i < 4; i++) {
snprintf(request, sizeof request, choose, texts[i]);
char *team_call = thinkthen_call(tt, request);
assert(team_call);
enum json_tokener_error parse_error;
struct json_object *result =
json_tokener_parse_verbose(team_call, &parse_error);
assert(parse_error == json_tokener_success);
assert(result && json_object_get_type(result)
== json_type_object);
struct json_object *value;
json_bool has_value = json_object_object_get_ex(
result, "value", &value);
assert(has_value);
struct json_object *facts;
json_bool has_facts = json_object_object_get_ex(
result, "facts", &facts);
assert(has_facts);
assert(facts && json_object_get_type(facts)
== json_type_object);
struct json_object *wanted =
json_tokener_parse_verbose(teams[i], &parse_error);
assert(parse_error == json_tokener_success);
assert(json_object_equal(value, wanted));
if (wanted) json_object_put(wanted);
json_object_put(result);
thinkthen_free_string(team_call);
}
thinkthen_engine_free(tt);Keep the #include lines on top. Put the rest inside int main(void) and end it with return 0;.
No C++ sample for choose.
No Objective-C sample for choose.
No COBOL sample for choose.
No Ada sample for choose.
No Java sample for choose.
No Kotlin sample for choose.
No Scala sample for choose.
No C# sample for choose.
No Go sample for choose.
No Swift sample for choose.
No Zig sample for choose.
No PHP sample for choose.
No Dart sample for choose.
No DuckDB sample for choose.
.load ./thinkthen
WITH t(body) AS (VALUES
('Please refund the extra fee on my invoice.'),
('My parcel went to the wrong address.'),
('I cannot reset my password.'),
('My parcel never came, and now ' ||
'I cannot log in to track it.'))
SELECT
thinkthen_choose(
'{"choose": "Which team owns this?",
"options": {
"billing": "Invoices, fees, and refunds.",
"shipping": "Parcels and delivery.",
"account": "Logins and passwords."
},
"threshold": 0.9}',
body
) AS team,
body
FROM t;billing|Please refund the extra fee on my invoice. shipping|My parcel went to the wrong address. account|I cannot reset my password. |My parcel never came, and now I cannot log in to track it.
SELECT id, thinkthen_choose(
'{"choose": "Which team owns this?",
"options": {
"billing": "Invoices, fees, and refunds.",
"shipping": "Parcels and delivery.",
"account": "Logins and passwords."
},
"threshold": 0.9}',
body, NULL) AS team
FROM (VALUES
(1, 'Please refund the extra fee on my invoice.'),
(2, 'My parcel went to the wrong address.'),
(3, 'I cannot reset my password.'),
(4, 'My parcel never came, and now ' ||
'I cannot log in to track it.')
) AS t(id, body);id | team ----+---------- 1 | billing 2 | shipping 3 | account 4 | (4 rows)
Arguments, options, and more examples
Jobs that use choose
Watch choose answer questions about Beatles songs: choose selects one option.
On GitHub: github.com/botassembly/thinkthen