The Bash example opens this page.
decide: answer one yes or no question about the evidence.
question="Does the customer ask for a refund?"
cat <<'EOF' |
Please refund my order. It arrived broken.
Thanks for the quick help yesterday!
I want to send this back.
EOF
thinkthen decide "$question" \
--batch 1 \
--lines \
--threshold 0.2:0.8 |
jq .{
"input": "Please refund my order. It arrived broken.",
"value": true
}
{
"input": "Thanks for the quick help yesterday!",
"value": false
}
{
"input": "I want to send this back.",
"value": null
}You give it one question and one piece of evidence. You get back true, false, or null.
Read the answer
On one piece of evidence, a probability inside the band prints null and exits 3. In a stream, that record prints null and the run exits 0.
| Exit code | What it means |
|---|---|
| 0 | yes |
| 1 | no |
| 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
No Python sample for decide.
import polars as pl
import thinkthen as tt
question = "Does the customer ask for a refund?"
tickets = pl.DataFrame({
"body": [
"Please refund my order. It arrived broken.",
"Thanks for the quick help yesterday!",
],
})
is_refund = tt.decide(question, tickets["body"]).value
tickets = tickets.with_columns(is_refund=is_refund)
assert tickets["is_refund"].to_list() == [True, False]No pandas sample for decide.
import assert from "node:assert/strict";
import * as tt from "thinkthen";
const question = "Does the customer ask for a refund?";
const broken = "Please refund my order. It arrived broken.";
const thanks = "Thanks for the quick help yesterday!";
const brokenIsRefund = (await tt.decide(
question, broken,
)).value;
const thanksIsRefund = (await tt.decide(
question, thanks,
)).value;
assert.equal(brokenIsRefund, true);
assert.equal(thanksIsRefund, false);require "thinkthen"
question = "Does the customer ask for a refund?"
broken = "Please refund my order. It arrived broken."
thanks = "Thanks for the quick help yesterday!"
broken_is_refund = ThinkThen.decide(question, broken).value
thanks_is_refund = ThinkThen.decide(question, thanks).value
raise unless broken_is_refund == true
raise unless thanks_is_refund == falselibrary(thinkthen)
question <- "Does the customer ask for a refund?"
texts <- c(
"Please refund my order. It arrived broken.",
"Thanks for the quick help yesterday!"
)
is_refund <- tt_decide(question, texts)$value
stopifnot(identical(is_refund, c(TRUE, FALSE)))use thinkthen::{Answer, Engine, Question};
let tt = Engine::from_env()?;
let question = "Does the customer ask for a refund?";
let refund = Question::decide(question)?.cut();
let broken = "Please refund my order. It arrived broken.";
let thanks = "Thanks for the quick help yesterday!";
let broken_is_refund = tt.decide(&refund, broken)?
.into_value();
let thanks_is_refund = tt.decide(&refund, thanks)?
.into_value();
assert_eq!(broken_is_refund, Answer::Yes);
assert_eq!(thanks_is_refund, Answer::No);Put this code inside fn main() -> Result<(), Box<dyn std::error::Error>> and end it with Ok(()). main returns a Result, so ? compiles.
#include <assert.h>
#include <string.h>
#include <thinkthen.h>
thinkthen_engine *tt = thinkthen_engine_new();
assert(tt);
const char *question =
"Does the customer ask for a refund?";
const char *text =
"Please refund my order. It arrived broken.";
thinkthen_answer is_refund;
int rc = thinkthen_decide(
tt,
question,
text,
strlen(text),
&is_refund
);
assert(rc == THINKTHEN_OK);
assert(is_refund.outcome == THINKTHEN_YES);
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 decide.
No Objective-C sample for decide.
No COBOL sample for decide.
No Ada sample for decide.
No Java sample for decide.
No Kotlin sample for decide.
No Scala sample for decide.
No C# sample for decide.
No Go sample for decide.
No Swift sample for decide.
No Zig sample for decide.
No PHP sample for decide.
No Dart sample for decide.
No DuckDB sample for decide.
.load ./thinkthen
WITH t(body) AS (VALUES
('Please refund my order. It arrived broken.'),
('Thanks for the quick help yesterday!'))
SELECT
thinkthen_decide(
'Does the customer ask for a refund?',
body
) AS is_refund,
body
FROM t;1|Please refund my order. It arrived broken. 0|Thanks for the quick help yesterday!
No PostgreSQL sample for decide.
Arguments, options, and more examples
Jobs that use decide
Watch decide answer questions about Beatles songs: decide answers yes, no, or not sure.
On GitHub: github.com/botassembly/thinkthen