pig/provider

The provider abstraction and metadata setters used by pig and its generated consumers.

A Provider is just a function from messages + tools to an InferenceResult. Concrete providers (Chat Completions, Codex Responses, etc.) live behind constructors that hide their transport details. pig/openai provides the standard OpenAI-shaped one.

Types

Metadata returned by the provider alongside the message.

pub type InferenceMetadata =
  inference.InferenceMetadata

Result of a provider call — the message plus metadata from the API response.

pub type InferenceResult =
  inference.InferenceResult

A provider is a function that takes messages and tool definitions, calls an LLM, and returns either an inference result or an error.

pub type Provider =
  fn(List(message.Message), List(tool_definition.ToolDefinition)) -> Result(
    inference.InferenceResult,
    error.AiError,
  )

Values

pub fn default_metadata() -> inference.InferenceMetadata

Create an InferenceMetadata with all fields set to None.

pub fn from_message(
  msg: message.Message,
) -> inference.InferenceResult

Wrap a bare Message into an InferenceResult with default (all-None) metadata.

pub fn with_input_tokens(
  meta: inference.InferenceMetadata,
  tokens: Int,
) -> inference.InferenceMetadata

Set input_tokens on metadata.

pub fn with_output_tokens(
  meta: inference.InferenceMetadata,
  tokens: Int,
) -> inference.InferenceMetadata

Set output_tokens on metadata.

pub fn with_response_id(
  meta: inference.InferenceMetadata,
  id: String,
) -> inference.InferenceMetadata

Set response_id on metadata.

pub fn with_response_model(
  meta: inference.InferenceMetadata,
  model: String,
) -> inference.InferenceMetadata

Set response_model on metadata.

pub fn with_stop_reason(
  meta: inference.InferenceMetadata,
  reason: stop_reason.StopReason,
) -> inference.InferenceMetadata

Set stop_reason on metadata.

Search Document