Tune.Predictor (Tune v0.5.0)

Copy Markdown View Source

An immutable typed predictor: a signature and its demonstrations.

prepare/3 and finish/2 are pure. call/3 composes them with one ReqLLM.generate_text/3 request. There is no retry, repair, extraction call, or format fallback; ReqLLM owns transport retries.

Summary

Functions

Prepares, executes one ReqLLM request, and finishes.

Checks a response against a prepared request and returns a validated step.

Builds a predictor.

Validates inputs and renders a request with the configured adapter.

Returns the predictor with new validated demonstrations.

Returns the predictor with new instructions.

Types

t()

@type t() :: %Tune.Predictor{demos: [Tune.Demo.t()], signature: Tune.Signature.t()}

Functions

call(predictor, inputs, config, remaining_ms \\ nil)

@spec call(t(), map(), Tune.ModelConfig.t(), non_neg_integer() | nil) ::
  {:ok, Tune.Step.t()} | {:error, Exception.t() | term()}

Prepares, executes one ReqLLM request, and finishes.

Input errors return before any request. A ReqLLM error is returned unchanged. remaining_ms caps the request's :total_timeout.

finish(prepared, response)

@spec finish(Tune.Prepared.t(), ReqLLM.Response.t()) ::
  {:ok, Tune.Step.t()} | {:error, Exception.t()}

Checks a response against a prepared request and returns a validated step.

The response must have no error or refusal and a completed finish reason: :stop, or :tool_calls for structured output only. Structured output must be strictly valid with no ReqLLM repair. Makes no model request.

new(opts)

@spec new(keyword()) :: {:ok, t()} | {:error, Exception.t()}

Builds a predictor.

Options:

  • :signature - a Tune.Signature or signature options
  • :demos - demonstrations validated against the signature

prepare(predictor, inputs, config)

@spec prepare(t(), map(), Tune.ModelConfig.t()) ::
  {:ok, Tune.Prepared.t()} | {:error, Exception.t()}

Validates inputs and renders a request with the configured adapter.

Makes no model request and holds no credentials.

put_demos(predictor, demos)

@spec put_demos(t(), list()) :: {:ok, t()} | {:error, Exception.t()}

Returns the predictor with new validated demonstrations.

put_instructions(predictor, instructions)

@spec put_instructions(t(), String.t()) :: {:ok, t()} | {:error, Exception.t()}

Returns the predictor with new instructions.