Skip to main content

ModelAdapter

Trait ModelAdapter 

Source
pub trait ModelAdapter: Send + Sync {
    // Required methods
    fn system_name(&self) -> &'static str;
    fn default_model(&self) -> &str;
    fn chat<'life0, 'async_trait>(
        &'life0 self,
        request: ModelRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ModelResponse, ModelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn structured_output<'life0, 'async_trait>(
        &'life0 self,
        request: StructuredRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ModelResponse, ModelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Unified interface for LLM providers.

Implement this trait to add a new model provider. The system string returned by system_name() is used as the gen_ai.system OTel attribute.

Required Methods§

Source

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

OTel GenAI system name (e.g. “anthropic”, “openai”).

Source

fn default_model(&self) -> &str

Default model for this adapter (e.g. “claude-sonnet-4-6”).

Source

fn chat<'life0, 'async_trait>( &'life0 self, request: ModelRequest, ) -> Pin<Box<dyn Future<Output = Result<ModelResponse, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a chat request and return the response.

Source

fn structured_output<'life0, 'async_trait>( &'life0 self, request: StructuredRequest, ) -> Pin<Box<dyn Future<Output = Result<ModelResponse, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a structured output request, returning a JSON value.

The response is validated against request.output_schema if possible.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§