Skip to main content

Module provider

Module provider 

Source
Expand description

Provider trait and request types.

This module defines two core abstractions:

  • Provider — the trait every backend implements. It uses Rust 2024’s native async-fn-in-traits (AFIT), so implementations are straightforward async fns with no macro overhead.

  • DynProvider — an object-safe mirror of Provider that uses boxed futures. A blanket impl<T: Provider> DynProvider for T bridges the two, so any concrete provider can be stored as Box<dyn DynProvider> or Arc<dyn DynProvider> with zero boilerplate.

§When to use which

SituationUse
Generic code that knows the concrete typeProvider
Need to store providers in a collection or behind dynDynProvider
Implementing a new backendimpl Provider for MyBackend

§Request parameters

All request configuration lives in ChatParams. It serializes cleanly to JSON (for logging / replay) with the exception of timeout and extra_headers, which are transport concerns and are #[serde(skip)]’d.

Structs§

ChatParams
Parameters for a chat completion request.
JsonSchema
A JSON Schema document used for structured output or tool parameters.
ProviderMetadata
Describes a provider instance: its name, model, and capabilities.
ToolDefinition
A tool the model can invoke during generation.
ToolRetryConfig
Configuration for automatic retries when a tool execution fails.

Enums§

Capability
A feature that a provider may or may not support.
ToolChoice
Controls whether the model should use tools and, if so, which ones.

Traits§

DynProvider
Object-safe counterpart of Provider for dynamic dispatch.
Provider
The core trait every LLM provider implements.

Type Aliases§

RetryPredicate
Retry behavior predicate type.