TypeSafe.SystemOne (TypeSafe AI v0.1.0-alpha.1)

Copy Markdown View Source

Layer 2 for the evaluation endpoint: typed questions in, typed answers out.

This module is the seam between the caller's structs and TypeSafe.HTTP. It validates questions locally, records the caller's keys, encodes the body, posts it, and decodes the answers back under the caller's keys. Everything that can fail before the network does so with a :validation error and no request is sent.

prepare/1 and evaluate_prepared/4 split the work so TypeSafe.evaluate_many/4 can validate and encode a question set once and reuse it for every state.

Summary

Types

The state to evaluate: text, or JSON-shaped structured data.

Functions

Evaluates state against questions.

Evaluates state against a question set from prepare/1.

Per-call options accepted by evaluate/4.

The evaluation endpoint path.

Validates and encodes a question set once, for reuse across many states.

Types

state()

@type state() :: String.t() | map() | list()

The state to evaluate: text, or JSON-shaped structured data.

Functions

evaluate(client, state, questions, opts \\ [])

@spec evaluate(TypeSafe.Client.t(), state(), TypeSafe.Question.input(), keyword()) ::
  {:ok, TypeSafe.Result.t()} | {:error, TypeSafe.Error.t()}

Evaluates state against questions.

See TypeSafe.evaluate/4 for the public entry point and examples.

evaluate_prepared(client, state, prepared, opts \\ [])

@spec evaluate_prepared(
  TypeSafe.Client.t(),
  state(),
  TypeSafe.SystemOne.Prepared.t(),
  keyword()
) ::
  {:ok, TypeSafe.Result.t()} | {:error, TypeSafe.Error.t()}

Evaluates state against a question set from prepare/1.

options_schema()

@spec options_schema() :: NimbleOptions.t()

Per-call options accepted by evaluate/4.

  • :model (String.t/0) - Model for this call; defaults to the client's model.

  • :timeout (pos_integer/0) - Timeout in milliseconds for this call.

  • :retry - Retry policy for this call; see TypeSafe.Retry.new/1.

  • :req_options (keyword/0) - Extra Req options for this call.

  • :telemetry (map/0) - Extra metadata merged into telemetry events.

path()

@spec path() :: String.t()

The evaluation endpoint path.

prepare(questions)

@spec prepare(TypeSafe.Question.input()) ::
  {:ok, TypeSafe.SystemOne.Prepared.t()} | {:error, TypeSafe.Error.t()}

Validates and encodes a question set once, for reuse across many states.