Skip to main content

InferenceProvider

Trait InferenceProvider 

Source
pub trait InferenceProvider: Send + Sync {
    // Required methods
    fn infer<'life0, 'life1, 'async_trait>(
        &'life0 self,
        req: &'life1 InferenceRequest,
    ) -> Pin<Box<dyn Future<Output = Result<InferenceResponse, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn name(&self) -> &str;
    fn model(&self) -> &ModelId;
    fn validate_config(&self) -> Result<(), Box<dyn Error + Send + Sync>>;

    // Provided method
    fn supports_tool_use(&self) -> bool { ... }
}
Expand description

Port: perform LLM inference.

Implementations decide the backend (Anthropic, OpenAI, local Ollama, etc.).

Required Methods§

Source

fn infer<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 InferenceRequest, ) -> Pin<Box<dyn Future<Output = Result<InferenceResponse, Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Run inference with the given request.

Source

fn name(&self) -> &str

Get the name of this provider.

Source

fn model(&self) -> &ModelId

Get the model being used.

Source

fn validate_config(&self) -> Result<(), Box<dyn Error + Send + Sync>>

Validate that this provider is properly configured.

Provided Methods§

Source

fn supports_tool_use(&self) -> bool

Whether this provider supports tool use (function calling).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§