Skip to main content

Provider

Trait Provider 

Source
pub trait Provider:
    Send
    + Sync
    + Debug {
    // Required methods
    fn kind(&self) -> &'static str;
    fn options(&self) -> ProviderOptions;
    fn set_options(&mut self, options: ProviderOptions);
    fn serialize_config(&self) -> Value;
    fn complete<'life0, 'async_trait>(
        &'life0 mut self,
        request: LlmRequest,
    ) -> Pin<Box<dyn Future<Output = Result<LlmResponse, ProviderFailure>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn clone_boxed(&self) -> Box<dyn Provider>;

    // Provided methods
    fn requires_streaming(&self) -> bool { ... }
    fn close<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), ProviderFailure>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

A configured LLM backend: its identity, host-config serialization, its generation options, and the request transport.

Required Methods§

Source

fn kind(&self) -> &'static str

Source

fn options(&self) -> ProviderOptions

Source

fn set_options(&mut self, options: ProviderOptions)

Source

fn serialize_config(&self) -> Value

Emit the provider-specific JSON body used by ProviderSpec. The object must NOT contain a type field — [ProviderSpec::Serialize] layers that on top.

Source

fn complete<'life0, 'async_trait>( &'life0 mut self, request: LlmRequest, ) -> Pin<Box<dyn Future<Output = Result<LlmResponse, ProviderFailure>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Source

fn clone_boxed(&self) -> Box<dyn Provider>

Provided Methods§

Source

fn requires_streaming(&self) -> bool

Source

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), ProviderFailure>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Release any host-visible transport resources this provider holds — cached connections, pooled sockets, background tasks — sending whatever graceful close a clean shutdown requires.

Hosts call this before process exit so protocol niceties (e.g. WebSocket Close frames) are sent rather than skipped by an abrupt drop. It takes &self because a provider’s reusable transport state lives behind its own synchronization; a shared clone can therefore be closed from the shutdown path. The default is a no-op: providers that hold no reusable transport state have nothing to release.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§