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

Copy Markdown View Source

A fully decoded response: every answer keyed by the caller's own question ids, plus usage and the raw decoded body for anything this layer doesn't expose yet.

Decoding is strict about the envelope (model and usage must be present and well-formed, every question must have an answer) but permissive about the payload: an answer the caller never asked for is dropped from answers but stays reachable through raw.

request_id is the x-typesafe-request-id response header, the value TypeSafe support asks for. TypeSafe.Error carries the same field for failed calls.

Summary

Functions

Decodes a response body against the questions that were sent.

Types

t()

@type t() :: %TypeSafe.Result{
  answers: %{required(TypeSafe.Keys.key()) => TypeSafe.Answer.t()},
  model: String.t(),
  raw: map(),
  request_id: String.t() | nil,
  usage: TypeSafe.Usage.t()
}

Functions

decode(body, questions, keys)

@spec decode(map(), [{TypeSafe.Keys.key(), TypeSafe.Question.t()}], TypeSafe.Keys.t()) ::
  {:ok, t()} | {:error, TypeSafe.Error.t()}

Decodes a response body against the questions that were sent.

questions is the normalized [{id, question}] list (see TypeSafe.Question.normalize/1) and keys is the TypeSafe.Keys built from it, so answers come back keyed and valued under the caller's own ids.