Skip to content

Answering many texts

There is no batch endpoint. Each call answers one text, so a list of texts is a loop of calls. The app's own file runs work this way too. They send eight rows at a time, each with its own idempotency key.

The loop needs three things:

  • A few calls at a time. Start with three in flight. Each call stays open until the model answers, which can take up to about 30 seconds. A key makes at most 600 calls a minute, and a call over that answers 429.
  • A client timeout above 30 seconds. Sending a text explains why. The examples use 45 seconds.
  • An idempotency key per record. Run the same list again and every record that already succeeded comes back from storage without asking the model, while every failed one is retried. A run that stopped halfway resumes where it left off.

Each example reads tickets.json, sends each ticket with format=jsonl, and writes the rows to answers.jsonl. With jsonl, every response is one line of JSON, so the output file is the responses joined together.

tickets.json
[
{
"id": "8812",
"subject": "Charged twice this month",
"body": "Hi, I was billed twice for September. Please refund the second charge before Friday."
},
{
"id": "8813",
"subject": "Calendar sync stopped",
"body": "Since this morning none of our appointments show up in Google Calendar."
}
]

The shell version needs jq to turn tickets.json into one request body per line, then xargs runs three curl calls at a time.

jq -c '.[] | {
ref: ("TCK-" + .id),
idempotency_key: ("tck-" + .id + "-1"),
fields: { subject: .subject, text: .body }
}' tickets.json |
tr '\n' '\0' |
xargs -0 -n 1 -P 3 curl -sS --fail --max-time 45 \
-H "Authorization: Bearer $PRISMLET_API_KEY" \
-H "Content-Type: application/json" \
"https://api.prismlet.com/v1/prisms/support-routing/results?format=jsonl" \
-d > answers.jsonl

xargs puts each body after -d. With --fail, only answered rows reach answers.jsonl, and curl names each failing status on stderr. Run the same command again to fill the gaps. Answered tickets come back from storage and failed ones are retried. A 400 repeats on every run until you fix that ticket.

Each line of answers.jsonl is one row: result_id, ref, version, status, error, created_at, the fields, then one column per question. A row with "status": "failed" carries its error and has null answer columns. Run the script again to retry those. Their keys retry them, and the rows that were already answered come back unchanged, without asking the model.

problems holds calls that got no row: a status other than 200 or 502, a timeout or a network error. Running again fixes timeouts, network errors, 429s and 500s. A 400, such as a text over 100,000 characters, repeats until you fix the record. The JavaScript and Python versions write rows in the order of tickets.json, and the curl version writes them as calls finish.

If you'd rather have a spreadsheet, use format=csv and keep only the first response's header row.

A key stands for one answer to one record. The examples use tck-<id>-1. If a ticket's text changes and you want it answered again, change the suffix to -2. The old key would return the old answer.

A key is forgotten when its result is deleted at the end of the account's retention period. Running an old list again after that answers every record again, as new calls.

Don't reuse a key scheme between prisms. Errors and retries explains why.

A prism's file runner, at /prisms/{id}/try#file, runs a whole file without any code. An admin opens it with Answer a file in the ... menu of the prism's Results, and an operator finds it on their Try tab.

  • The file is CSV, TSV or JSON, told apart by its extension. A .txt file is read as TSV or CSV, whichever it looks like. In CSV and TSV the first row is the column names. A JSON file is an array of objects, and its keys are the column names.
  • A file holds at most 10,000 rows and 200 MiB. Blank lines are skipped. A file that is not valid UTF-8 is read as Windows-1252. Keep the tab open while it runs; a large file of long texts can take most of an hour.
  • Every field needs a column, and the reference column is optional. The app matches columns by name, and Change shows each match. Without a reference column, or where its cell is blank, the reference is the row number.
  • Optionally, a column for the context. Each row's cell is sent as that call's context, after the prism's own. An empty cell sends none.
  • Each row is answered by the latest saved version, live or not, and saved as a result with the file as its source, so it shows in Results like any other.
  • Running the same file again with the same columns chosen, on the same prism version, resumes: answered rows come back from storage and failed ones are retried. Choosing other field, reference or context columns, or saving a new version of the prism, answers every row again.
  • The answered file is the original columns, then one column per question, then result_id, in the file's own format. CSV and TSV cells hold labels. A JSON file holds keys, and every original value comes back as a string.
  • An answer column or result_id that has the same name as an original column gets a number suffix, such as urgent_2, so your own columns are kept.
  • A row the app could not send, for example one with a reference over 200 characters, is counted as not saved and has no result.

If the file already holds the answers you expect, from your QA team for example, choose that column under Your answers for each question you want checked. After the run the app shows how often its answers match yours.

  • Yes / No cells can be yes, no, y, n, true, false, 1 or 0. Choice cells can be an option's key or label, including Other and Not enough information. Scale cells can be a level's key, its label or its number counting from 1. Case and surrounding spaces don't matter.
  • A blank cell leaves that row out of the check. Any other value the app can't read is left out and counted, with a few examples shown.
  • Nothing labelled is dropped silently. Rows the app could not send are counted as not run, provider failures as failed, an answer naming no option the question offers as no valid answer, and Other, Not enough information and Unsure together as Unsure. A no valid answer is always a miss, and so is each of the others, in every figure. The own cutoffs row also shows the share that was Unsure.
  • Every percentage shows its sample beside it, such as 62% (31 of 50), and Download evaluation has each figure's two counts in the columns after it.
  • Yes / No shows agreement, recall and precision for Yes at cutoffs from 10% to 90%, plus a row for the question's own cutoffs, such as Own cutoffs, Yes from 70%, No below 35%, which also shows the share that fell between them. An Unsure answer counts as a miss in that row's agreement and recall, and it is listed as a miss.
  • Choice shows agreement, precision and recall per option, and agreement when only answers with a top probability from 50% to 90% are counted, with the share of rows that leaves.
  • Scale shows exact agreement and agreement within one level.
  • Group by splits the headline figures by a column, such as language, site or team. A Yes / No group also shows its share between its cutoffs, which its agreement leaves out.
  • Every row where the answers differ is listed as a miss. Download evaluation saves the figures as CSV, and Download misses saves every miss with its reference and result_id.
  • Running sends only the field columns, and the context column when you choose one. Your answers and the group column stay in the browser unless you save the file as a test set.
  • Changing the columns of your answers or the group column after a run updates the figures without asking the model again. To compare two versions of the prism, run the file once on each, or save it as a test set.

On the prism's Test tab, Choose a file maps a file's columns the same way, and Save as test set keeps the rows as texts: each row's fields, reference, context, group and your answers. Run the set there on any saved version, live or not.

  • A test set holds at most 1,000 texts and 5 MB of them. Your answers are stored as option keys; one the app can't read is left out and counted when you save.
  • Add texts with your answers adds a file's texts to the set in view. A run keeps pointing at the texts it answered, so old runs stay comparable.
  • A run asks the model once per text, eight at a time, and the Test tab says how many calls before you start. Keep the tab open; a run that stopped resumes with the texts that have no answer yet, and a failed text is asked again. An answered text is never asked twice.
  • Test run answers are not results. They don't show in Results or exports, and they are read with the cutoffs of the version that ran. Download misses names each text by case_id instead of result_id.
  • A text keeps its id when you add the file again to the same set: rows are matched to the set's texts by reference, so references must be unique within a set.
  • Test texts that reach the model count against a per-account limit a minute; the Test tab waits and goes on when it is reached.
  • The Test tab runs a set, says how a run matches your answers, compares two runs on the same texts question by question, opens their texts and gives each change with its range. Testing explains each view and how a verdict is reached.
  • A set of 50 texts or more keeps about one text in five back, chosen by the text's id so it stays the same when the set changes. Kept-back texts are reported only as counts and rates, and never listed, so nobody tunes a prism to them.
  • A result that kept its text can be added to a set from Results. See Add to a test set.
  • A test set keeps its texts whatever the prism keeps of the text, so a prism that keeps no text asks you to confirm first. Results retention does not reach test sets: they are kept until you delete the set, or its older runs.