pig/provider
Streaming-first provider boundary for pig.
A Provider owns how an inference is started; an Inference owns its
cancellable event stream. The coordinator below is the only layer that
decides inference terminality, so exactly one Finished event crosses the
boundary even when a source races cancellation or emits late events.
Types
Events emitted by an inference. Finished is emitted exactly once.
pub type InferenceEvent {
Delta(inference.InferenceDelta)
Finished(Result(inference.InferenceResult, error.AiError))
}
Constructors
-
Delta(inference.InferenceDelta) -
Finished(Result(inference.InferenceResult, error.AiError))
Metadata returned by the provider alongside the message.
pub type InferenceMetadata =
inference.InferenceMetadata
The messages, tools, and settings for one provider call.
pub type InferenceRequest {
InferenceRequest(
messages: List(message.Message),
tools: List(tool_definition.ToolDefinition),
settings: InferenceSettings,
)
}
Constructors
-
InferenceRequest( messages: List(message.Message), tools: List(tool_definition.ToolDefinition), settings: InferenceSettings, )
Result of a provider call - the message plus metadata from the API response.
pub type InferenceResult =
inference.InferenceResult
Inference settings passed to a provider.
pub type InferenceSettings {
InferenceSettings(thinking: ThinkingSetting)
}
Constructors
-
InferenceSettings(thinking: ThinkingSetting)
An opaque provider that starts asynchronous inference work.
pub opaque type Provider
The thinking configuration for one inference request.
pub type ThinkingSetting {
UseProviderDefault
UseThinkingLevel(thinking.ThinkingLevel)
}
Constructors
-
UseProviderDefault -
UseThinkingLevel(thinking.ThinkingLevel)
Values
pub fn cancel(inference: Inference) -> Nil
Cancel an inference. Repeated cancellation is harmless.
pub fn collect(
inference: Inference,
timeout_ms: Int,
) -> Result(inference.InferenceResult, error.AiError)
Collect an inference for transitional synchronous callers. Timeout cancels.
pub fn default_metadata() -> inference.InferenceMetadata
Create an InferenceMetadata with all fields set to None.
pub fn default_settings() -> InferenceSettings
Return settings that defer thinking configuration to the provider.
pub fn from_buffered(
call: fn(InferenceRequest) -> Result(
inference.InferenceResult,
error.AiError,
),
) -> Provider
Build a provider from the existing buffered provider shape.
pub fn from_message(
msg: message.Message,
) -> inference.InferenceResult
Wrap a bare Message into an InferenceResult with default metadata.
pub fn from_streaming(
start: fn(InferenceRequest, fn(InferenceEvent) -> Nil) -> Nil,
) -> Provider
Build a provider from a source that may emit normalized events.
pub fn from_streaming_with_timeout(
start: fn(InferenceRequest, fn(InferenceEvent) -> Nil) -> Nil,
update_timeout: fn(Int) -> Provider,
) -> Provider
Build a provider with a provider-specific timeout update.
pub fn receive(
inference: Inference,
timeout_ms: Int,
) -> Result(InferenceEvent, Nil)
Receive the next inference event from its handle.
pub fn run(
provider: Provider,
request: InferenceRequest,
timeout_ms: Int,
) -> Result(inference.InferenceResult, error.AiError)
Start and collect one inference for transitional synchronous callers.
pub fn settings_from_string(
value: String,
) -> Result(InferenceSettings, Nil)
Decode the stable provider-neutral representation of inference settings.
pub fn settings_to_string(settings: InferenceSettings) -> String
Encode inference settings using the stable provider-neutral representation.
pub fn start(
provider: Provider,
request: InferenceRequest,
) -> Inference
Start inference and return immediately with an opaque handle.
pub fn with_default_thinking_level(
provider: Provider,
level: thinking.ThinkingLevel,
) -> Provider
Set the provider fallback thinking level. Request-level settings still win.
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.
pub fn with_thinking_level(
level: thinking.ThinkingLevel,
) -> InferenceSettings
Return settings requesting the given thinking level.