pub trait Provider: Send + Sync {
Show 21 methods
// Required methods
fn metadata() -> ProviderMetadata
where Self: Sized;
fn get_name(&self) -> &str;
fn complete_with_model<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
model_config: &'life1 ModelConfig,
system: &'life2 str,
messages: &'life3 [Message],
tools: &'life4 [Tool],
) -> Pin<Box<dyn Future<Output = Result<(Message, ProviderUsage), ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait;
fn get_model_config(&self) -> ModelConfig;
// Provided methods
fn complete<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system: &'life1 str,
messages: &'life2 [Message],
tools: &'life3 [Tool],
) -> Pin<Box<dyn Future<Output = Result<(Message, ProviderUsage), ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn complete_fast<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system: &'life1 str,
messages: &'life2 [Message],
tools: &'life3 [Tool],
) -> Pin<Box<dyn Future<Output = Result<(Message, ProviderUsage), ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn retry_config(&self) -> RetryConfig { ... }
fn fetch_supported_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn fetch_recommended_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn map_to_canonical_model<'life0, 'life1, 'async_trait>(
&'life0 self,
provider_model: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn supports_embeddings(&self) -> bool { ... }
fn supports_cache_control<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn create_embeddings<'life0, 'async_trait>(
&'life0 self,
_texts: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn as_lead_worker(&self) -> Option<&dyn LeadWorkerProviderTrait> { ... }
fn stream<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_system: &'life1 str,
_messages: &'life2 [Message],
_tools: &'life3 [Tool],
) -> Pin<Box<dyn Future<Output = Result<MessageStream, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn supports_streaming(&self) -> bool { ... }
fn get_active_model_name(&self) -> String { ... }
fn get_initial_user_messages(&self, messages: &Conversation) -> Vec<String> { ... }
fn generate_session_name<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 Conversation,
) -> Pin<Box<dyn Future<Output = Result<String, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn create_session_name_prompt(&self, context: &[String]) -> String { ... }
fn configure_oauth<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Base trait for AI providers (OpenAI, Anthropic, etc)
Required Methods§
Sourcefn metadata() -> ProviderMetadatawhere
Self: Sized,
fn metadata() -> ProviderMetadatawhere
Self: Sized,
Get the metadata for this provider type
fn complete_with_model<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
model_config: &'life1 ModelConfig,
system: &'life2 str,
messages: &'life3 [Message],
tools: &'life4 [Tool],
) -> Pin<Box<dyn Future<Output = Result<(Message, ProviderUsage), ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Sourcefn get_model_config(&self) -> ModelConfig
fn get_model_config(&self) -> ModelConfig
Get the model config from the provider
Provided Methods§
fn complete<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system: &'life1 str,
messages: &'life2 [Message],
tools: &'life3 [Tool],
) -> Pin<Box<dyn Future<Output = Result<(Message, ProviderUsage), ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn complete_fast<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
system: &'life1 str,
messages: &'life2 [Message],
tools: &'life3 [Tool],
) -> Pin<Box<dyn Future<Output = Result<(Message, ProviderUsage), ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn retry_config(&self) -> RetryConfig
fn fetch_supported_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn fetch_recommended_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn fetch_recommended_models<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Fetch models filtered by canonical registry and usability
fn map_to_canonical_model<'life0, 'life1, 'async_trait>(
&'life0 self,
provider_model: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn supports_embeddings(&self) -> bool
fn supports_cache_control<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn create_embeddings<'life0, 'async_trait>(
&'life0 self,
_texts: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create_embeddings<'life0, 'async_trait>(
&'life0 self,
_texts: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Create embeddings if supported. Default implementation returns an error.
Sourcefn as_lead_worker(&self) -> Option<&dyn LeadWorkerProviderTrait>
fn as_lead_worker(&self) -> Option<&dyn LeadWorkerProviderTrait>
Check if this provider is a LeadWorkerProvider This is used for logging model information at startup
fn stream<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_system: &'life1 str,
_messages: &'life2 [Message],
_tools: &'life3 [Tool],
) -> Pin<Box<dyn Future<Output = Result<MessageStream, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn supports_streaming(&self) -> bool
Sourcefn get_active_model_name(&self) -> String
fn get_active_model_name(&self) -> String
Get the currently active model name For regular providers, this returns the configured model For LeadWorkerProvider, this returns the currently active model (lead or worker)
Sourcefn get_initial_user_messages(&self, messages: &Conversation) -> Vec<String>
fn get_initial_user_messages(&self, messages: &Conversation) -> Vec<String>
Returns the first 3 user messages as strings for session naming
Sourcefn generate_session_name<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 Conversation,
) -> Pin<Box<dyn Future<Output = Result<String, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn generate_session_name<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 Conversation,
) -> Pin<Box<dyn Future<Output = Result<String, ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate a session name/description based on the conversation history Creates a prompt asking for a concise description in 4 words or less.
fn create_session_name_prompt(&self, context: &[String]) -> String
Sourcefn configure_oauth<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn configure_oauth<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Configure OAuth authentication for this provider
This method is called when a provider has configuration keys marked with oauth_flow = true. Providers that support OAuth should override this method to implement their specific OAuth flow.
§Returns
Ok(())if OAuth configuration succeeds and credentials are savedErr(ProviderError)if OAuth fails or is not supported by this provider
§Default Implementation
The default implementation returns an error indicating OAuth is not supported.