ThinkThen

PostgreSQL functions that answer questions about text

One extension. Ask questions in any query.

Install

Channel
CREATE EXTENSION thinkthen;

Set THINKTHEN_API_KEY in the environment.

A first call

refund.json, a file the sample reads
{
  "decide": "Does the customer ask for a refund?",
  "threshold": "0.2:0.8"
}
CREATE TABLE tickets (id int, body text);
INSERT INTO tickets VALUES
    (1, 'Please refund my order. It arrived broken.'),
    (2, 'Thanks for the quick help yesterday!'),
    (3, 'I want to send this back.');

WITH judged AS (
    SELECT
        id,
        body,
        thinkthen_decide('@refund.json', body) AS is_refund
    FROM tickets
)
SELECT id, body FROM judged
WHERE is_refund IS NULL;
What PostgreSQL printed
 id |           body            
----+---------------------------
  3 | I want to send this back.
(1 row)

Not sure comes back as NULL. Branch on it and send those cases to a person. Each function page shows its PostgreSQL call.

Run facts

thinkthen_usage() gives the totals for the process.

Errors

A failed call raises its named error. thinkthen_try_details returns a failure as jsonb instead.

Settings and recording

SET thinkthen.record writes a recording to a folder. SET thinkthen.replay answers from that recording with no connection. The Settings page lists every setting.

What is different in PostgreSQL