# Ada functions that answer questions about text

A `Thinkthen` package over the C library, for GNAT. Each call is a procedure with out parameters.

## Install

| Channel | Note |
| --- | --- |
| `thinkthen-ada-VERSION-TARGET.tar.gz` | The package and its GNAT project, 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

```
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Thinkthen; use Thinkthen;

procedure First_Call is
   Client    : Engine;
   Is_Refund : Decision;
   Facts     : Unbounded_String;
   Error     : Failure;

   Question : constant String :=
     "Does the customer ask for a refund?";
   Refund   : constant String :=
     "{""decide"": """ & Question & """, "
     & """threshold"": ""0.2:0.8""}";
begin
   Decide
     (Client,
      Question,
      "Please refund my order. It arrived broken.",
      Is_Refund,
      Facts,
      Error);
   pragma Assert (Error.Kind = None);
   pragma Assert (Is_Refund.Value = Yes);

   Decide
     (Client,
      Refund,
      "I want to send this back.",
      Is_Refund,
      Facts,
      Error);
   pragma Assert (Error.Kind = None);
   pragma Assert (Is_Refund.Value = Not_Sure);
end First_Call;
```

*Build and run it beside the unpacked archives, thinkthen-c/ and thinkthen-ada/*

```
gnatmake -gnat2022 -gnata \
    -Ithinkthen-ada/src \
    first_call.adb -o first_call \
    -largs \
    -L thinkthen-c/lib -lthinkthen \
    -Wl,-rpath,"$PWD/thinkthen-c/lib"
./first_call
```

Not sure comes back as `Not_Sure`. Branch on it and send those cases to a person.

## Run facts

`Decide` sets `Facts` to this call's run facts as JSON text. `Member` reads one member.

## Errors

`Decide` sets `Error`. Its `Kind` runs from `Usage` to `Defect`, and `None` means the call answered.

## Settings and recording

`Configure` takes the settings as JSON. `"record"` writes a recording to a folder. `"replay"` answers from that recording with no connection. The [Settings](/install/settings/) page lists every setting.

## Jev, Liquid d1 and Ollama from Ada

Ada 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](/install/backends/typesafe/) | `typesafe` | `TYPESAFE_API_KEY` |
| [Liquid d1](/install/backends/liquid/) | `liquid` | `LIQUIDAI_API_KEY`, then `LIQUID_API_KEY` |
| [Ollama](/install/backends/ollama/) | `ollama` | `OLLAMA_API_KEY`. A local address needs no key. |

*Ask TypeSafe Jev.*

```
export THINKTHEN_BACKEND=typesafe
export TYPESAFE_API_KEY=...
```

*Ask Liquid d1.*

```
export THINKTHEN_BACKEND=liquid
export LIQUIDAI_API_KEY=...
```

*Ask Ollama. This block names a second port, 11535, as the site's runs do. On the default port, leave THINKTHEN_BASE_URL out.*

```
export THINKTHEN_BACKEND=ollama
export THINKTHEN_BASE_URL=http://localhost:11535/v1
```

```
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Thinkthen; use Thinkthen;

procedure Backends is
   Client           : Engine;
   Broken_Is_Refund : Decision;
   Thanks_Is_Refund : Decision;
   Facts            : Unbounded_String;
   Error            : Failure;

   Question : constant String :=
     "Does the customer ask for a refund?";
begin
   Decide
     (Client,
      Question,
      "Please refund my order. It arrived broken.",
      Broken_Is_Refund,
      Facts,
      Error);
   pragma Assert (Error.Kind = None);
   pragma Assert (Broken_Is_Refund.Value = Yes);

   Decide
     (Client,
      Question,
      "Thanks for the quick help yesterday!",
      Thanks_Is_Refund,
      Facts,
      Error);
   pragma Assert (Error.Kind = None);
   pragma Assert (Thanks_Is_Refund.Value = No);
end Backends;
```

*Build and run it beside the unpacked archives, thinkthen-c/ and thinkthen-ada/*

```
gnatmake -gnat2022 -gnata \
    -Ithinkthen-ada/src \
    backends.adb -o backends \
    -largs \
    -L thinkthen-c/lib -lthinkthen \
    -Wl,-rpath,"$PWD/thinkthen-c/lib"
./backends
```

The configuration file's `backend` names a default backend for every run. The [Configuration](/install/configuration/#configuration-file) page shows the file.

### OpenAI Decisions API from Ada

OpenAI announced its Decisions API on 2026-09-29 in its [DevDay 2026 recap](https://openai.com/index/devday-2026-recap/). OpenAI has published no address, schema or price, so ThinkThen cannot call it. The [OpenAI Decisions API](/install/backends/openai/) page says what ThinkThen knows.

## What is different in Ada

- `gprbuild -P thinkthen.gpr` builds the package as a library.
- `pragma Assert` runs only under `-gnata`.

On GitHub: [github.com/botassembly/thinkthen](https://github.com/botassembly/thinkthen)
