pig/ai/provider

Types

Metadata returned by the provider alongside the message.

pub type InferenceMetadata {
  InferenceMetadata(
    response_id: option.Option(String),
    response_model: option.Option(String),
    stop_reason: option.Option(stop_reason.StopReason),
    input_tokens: option.Option(Int),
    output_tokens: option.Option(Int),
  )
}

Constructors

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

pub type InferenceResult {
  InferenceResult(
    message: message.Message,
    metadata: InferenceMetadata,
  )
}

Constructors

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(
    InferenceResult,
    error.AiError,
  )

Values

pub fn default_metadata() -> InferenceMetadata

Create an InferenceMetadata with all fields set to None.

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

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

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

Set input_tokens on metadata.

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

Set output_tokens on metadata.

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

Set response_id on metadata.

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

Set response_model on metadata.

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

Set stop_reason on metadata.

Search Document