Tune.Adapter behaviour (Tune v0.5.0)

Copy Markdown View Source

A pure prompt format.

An adapter renders a signature, demonstrations, and inputs into a ReqLLM context and output descriptor, and parses a reply into a map of declared output fields. It never calls a model, retries, repairs, or falls back to another format. The caller validates the parsed map against the signature.

Summary

Types

A rendered request: the ReqLLM context and the output descriptor to request.

A reply to parse: raw response text for text output, or the validated structured value for object output.

Callbacks

Validates and normalizes adapter options once, when a model configuration is built.

Parses a reply into a string-keyed map of every declared output field.

Renders a request. Inputs are already normalized and validated.

Types

rendering()

@type rendering() :: %{context: ReqLLM.Context.t(), output: ReqLLM.Output.t()}

A rendered request: the ReqLLM context and the output descriptor to request.

reply()

@type reply() :: {:text, String.t()} | {:object, map()}

A reply to parse: raw response text for text output, or the validated structured value for object output.

Callbacks

normalize_options(keyword)

@callback normalize_options(keyword()) :: {:ok, keyword()} | {:error, Exception.t()}

Validates and normalizes adapter options once, when a model configuration is built.

parse(t, reply, keyword)

@callback parse(Tune.Signature.t(), reply(), keyword()) ::
  {:ok, map()} | {:error, Exception.t()}

Parses a reply into a string-keyed map of every declared output field.

render(t, list, map, keyword)

@callback render(Tune.Signature.t(), [Tune.Demo.t()], map(), keyword()) ::
  {:ok, rendering()} | {:error, Exception.t()}

Renders a request. Inputs are already normalized and validated.