Java functions that answer questions about text
One Door class over the C library, for Java 21. Each call returns its answer and its run facts.
Install
| Channel | Note |
|---|---|
io.github.botassembly:thinkthen-jvm:VERSION | The Maven coordinate. |
thinkthen-jvm-VERSION-TARGET.tar.gz | The door, Kotlin and Scala JARs, from each release. |
thinkthen-c-VERSION-TARGET.tar.gz | The C library it calls, from the same release. |
Set THINKTHEN_API_KEY in the environment.
A first call
import static java.nio.charset.StandardCharsets.UTF_8;
import thinkthen.Door;
import thinkthen.Door.Outcome;
public class FirstCall {
public static void main(String[] args) {
try (var tt = new Door()) {
var question =
"Does the customer ask for a refund?";
var isRefund = tt.decide(
question,
"Please refund my order. It arrived broken."
.getBytes(UTF_8));
assert Door.outcome(isRefund.value())
== Outcome.YES;
var refund = "{\"decide\": \"" + question
+ "\", \"threshold\": \"0.2:0.8\"}";
isRefund = tt.decide(
refund,
"I want to send this back."
.getBytes(UTF_8));
assert Door.outcome(isRefund.value())
== Outcome.NOT_SURE;
}
}
}javac --enable-preview --release 21 \
-cp thinkthen-jvm/thinkthen-door.jar \
FirstCall.java
java --enable-preview -ea \
--enable-native-access=ALL-UNNAMED \
-Dthinkthen.library="$PWD/thinkthen-c/lib/libthinkthen.so" \
-cp thinkthen-jvm/thinkthen-door.jar:. \
FirstCallNot sure comes back as Outcome.NOT_SURE. Branch on it and send those cases to a person.
Run facts
decide returns a TypedResult. Its value() holds the answer, and its facts() holds this call's run facts as a Map.
Errors
A failed call throws a Door.NativeFailure. Its failure names one of six FailureKind values, with the message and the retry flag.
Settings and recording
new Door(settingsJson) takes the settings as JSON. "record" writes a recording to a folder. "replay" answers from that recording with no connection. The Settings page lists every setting.
Jev, Liquid d1 and Ollama from Java
Java reads its backend from the environment. Set THINKTHEN_BACKEND to the name below. Set the backend's key variable in the shell, and the same sample asks that backend.
| Backend | Name | Key variable |
|---|---|---|
| TypeSafe Jev | typesafe | TYPESAFE_API_KEY |
| Liquid d1 | liquid | LIQUIDAI_API_KEY, then LIQUID_API_KEY |
| Ollama | ollama | OLLAMA_API_KEY. A local address needs no key. |
export THINKTHEN_BACKEND=typesafe
export TYPESAFE_API_KEY=...export THINKTHEN_BACKEND=liquid
export LIQUIDAI_API_KEY=...export THINKTHEN_BACKEND=ollama
export THINKTHEN_BASE_URL=http://localhost:11535/v1import static java.nio.charset.StandardCharsets.UTF_8;
import thinkthen.Door;
import thinkthen.Door.Outcome;
public class Backends {
public static void main(String[] args) {
try (var tt = new Door()) {
var question =
"Does the customer ask for a refund?";
var brokenIsRefund = tt.decide(
question,
"Please refund my order. It arrived broken."
.getBytes(UTF_8));
var thanksIsRefund = tt.decide(
question,
"Thanks for the quick help yesterday!"
.getBytes(UTF_8));
assert Door.outcome(brokenIsRefund.value())
== Outcome.YES;
assert Door.outcome(thanksIsRefund.value())
== Outcome.NO;
}
}
}javac --enable-preview --release 21 \
-cp thinkthen-jvm/thinkthen-door.jar \
Backends.java
java --enable-preview -ea \
--enable-native-access=ALL-UNNAMED \
-Dthinkthen.library="$PWD/thinkthen-c/lib/libthinkthen.so" \
-cp thinkthen-jvm/thinkthen-door.jar:. \
BackendsThe configuration file's backend names a default backend for every run. The Configuration page shows the file.
OpenAI Decisions API from Java
OpenAI announced its Decisions API on 2026-09-29 in its DevDay 2026 recap. OpenAI has published no address, schema or price, so ThinkThen cannot call it. The OpenAI Decisions API page says what ThinkThen knows.
What is different in Java
- The door calls the C library through Java 21's foreign function API.
javacandjavatake--enable-preview. -Dthinkthen.librarynames the C library by its absolute path.assertruns only underjava -ea.
On GitHub: github.com/botassembly/thinkthen