pandas functions that answer questions about text
A pandas Series goes in, and a Series with the same index comes back in Call.value.
Install
| Channel |
|---|
pip install thinkthen pandas |
Set THINKTHEN_API_KEY in the environment.
A first call
import pandas as pd
import thinkthen as tt
question = "Does the customer ask for a refund?"
refund = tt.question(decide=question, threshold=(0.2, 0.8))
messages = pd.Series(
[
"Please refund my order. It arrived broken.",
"I want to send this back.",
],
name="message",
)
is_refund = tt.decide(refund, messages).value
assert is_refund.dtype == "boolean"
assert is_refund.tolist() == [True, pd.NA]
for_a_person = messages[is_refund.isna()]
assert for_a_person.tolist() == [
"I want to send this back.",
]Not sure comes back as pd.NA. Branch on it and send those cases to a person.
Run facts
Call.facts counts this call.
Errors
Every failure raises a ThinkThenError, as in Python. Its subclass names the kind.
Settings and recording
tt.Engine takes each setting as a keyword, as in Python. record= writes a recording to a folder. replay= answers from that recording with no connection. The Settings page lists every setting.
Backends
pandas runs on the Python engine, so it reaches each backend the same way. The Python page shows Jev, Liquid d1 and Ollama.
What is different in pandas
decide,choose,scoreandtagtake a Series and keep its index and name.decidegives abooleanSeries,scoregivesFloat64,choosegivesstring, andtaggives one list of labels per row.annotatetakes a DataFrame withon=and adds one column per question.
On GitHub: github.com/botassembly/thinkthen