Scala functions that answer questions about text
A ScalaFacade over the Java door, for Scala 3. Its calls take strings.
Install
| Channel | Note |
|---|---|
io.github.botassembly:thinkthen-jvm:VERSION:scala | The Scala JAR. Add the Java coordinate beside it. |
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 scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Using
import thinkthen.Door
import thinkthen.Door.Outcome
@main def firstCall(): Unit =
Using.resource(Door()) { engine =>
val tt = ScalaFacade(engine)
val question =
"Does the customer ask for a refund?"
var isRefund = tt.decide(
question,
"Please refund my order. It arrived broken."
)
assert(Door.outcome(isRefund.value()) == Outcome.YES)
val refund =
s"""{"decide": "$question", """ +
""""threshold": "0.2:0.8"}"""
isRefund = tt.decide(
refund,
"I want to send this back."
)
val outcome = Door.outcome(isRefund.value())
assert(outcome == Outcome.NOT_SURE)
}scalac \
-cp thinkthen-jvm/thinkthen-door.jar:thinkthen-jvm/thinkthen-scala.jar \
-d FirstCall.jar FirstCall.scala
java --enable-preview -ea \
--enable-native-access=ALL-UNNAMED \
-Dthinkthen.library="$PWD/thinkthen-c/lib/libthinkthen.so" \
-cp thinkthen-jvm/thinkthen-door.jar:thinkthen-jvm/thinkthen-scala.jar:FirstCall.jar:"$SCALA_HOME/lib/scala.jar" \
firstCallNot sure comes back as Outcome.NOT_SURE. Branch on it and send those cases to a person.
Run facts
decide returns the door's TypedResult. value() holds the answer, and facts() holds this call's run facts as a Map.
Errors
A failed call throws a Door.NativeFailure, as in Java. Its failure names the kind, the message and the retry flag.
Settings and recording
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 Scala
Scala 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 scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Using
import thinkthen.Door
import thinkthen.Door.Outcome
@main def backends(): Unit =
Using.resource(Door()) { engine =>
val tt = ScalaFacade(engine)
val question =
"Does the customer ask for a refund?"
val brokenIsRefund = tt.decide(
question,
"Please refund my order. It arrived broken."
)
val thanksIsRefund = tt.decide(
question,
"Thanks for the quick help yesterday!"
)
val broken = Door.outcome(brokenIsRefund.value())
val thanks = Door.outcome(thanksIsRefund.value())
assert(broken == Outcome.YES)
assert(thanks == Outcome.NO)
}scalac \
-cp thinkthen-jvm/thinkthen-door.jar:thinkthen-jvm/thinkthen-scala.jar \
-d Backends.jar Backends.scala
java --enable-preview -ea \
--enable-native-access=ALL-UNNAMED \
-Dthinkthen.library="$PWD/thinkthen-c/lib/libthinkthen.so" \
-cp thinkthen-jvm/thinkthen-door.jar:thinkthen-jvm/thinkthen-scala.jar:Backends.jar:"$SCALA_HOME/lib/scala.jar" \
backendsThe configuration file's backend names a default backend for every run. The Configuration page shows the file.
OpenAI Decisions API from Scala
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 Scala
ScalaFacadetakes anExecutionContext.decideAsyncgives afuture, andclose()waits for the call.- The run needs the Scala library on the class path, such as
$SCALA_HOME/lib/scala.jar.
On GitHub: github.com/botassembly/thinkthen