pig_protocol/inference

Types

A provider-neutral piece of an assistant response.

Provider-specific stream fields are normalized into these four forms. Tool calls retain their provider index so parallel calls can be assembled without changing their order.

pub type InferenceDelta {
  TextDelta(text: String)
  ReasoningDelta(text: String)
  ToolCallStarted(index: Int, id: String, name: String)
  ToolArgumentDelta(index: Int, delta: String)
}

Constructors

  • TextDelta(text: String)

    A fragment of the assistant’s visible response.

  • ReasoningDelta(text: String)

    A fragment of the assistant’s reasoning or thinking output.

  • ToolCallStarted(index: Int, id: String, name: String)

    The first metadata for a tool call at a provider stream index.

  • ToolArgumentDelta(index: Int, delta: String)

    A fragment of JSON arguments for a tool call.

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

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