pub trait Model: Send + Sync {
// Required methods
fn id(&self) -> &str;
fn name(&self) -> &str;
fn provider_id(&self) -> &str;
fn capabilities(&self) -> &ModelCapabilities;
fn config(&self) -> &ModelConfig;
fn generate<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: GenerateOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: GenerateOptions,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn estimate_cost<'life0, 'async_trait>(
&'life0 self,
input_tokens: u32,
output_tokens: u32,
) -> Pin<Box<dyn Future<Output = Result<f64>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn metadata(&self) -> &ModelMetadata;
}
Expand description
Model trait for individual language models
Required Methods§
Sourcefn provider_id(&self) -> &str
fn provider_id(&self) -> &str
Provider that owns this model
Sourcefn capabilities(&self) -> &ModelCapabilities
fn capabilities(&self) -> &ModelCapabilities
Model capabilities
Sourcefn config(&self) -> &ModelConfig
fn config(&self) -> &ModelConfig
Model configuration
Sourcefn generate<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: GenerateOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn generate<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: GenerateOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generate a response from messages
Sourcefn stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: GenerateOptions,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
options: GenerateOptions,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream response generation
Sourcefn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Count tokens in messages
Sourcefn estimate_cost<'life0, 'async_trait>(
&'life0 self,
input_tokens: u32,
output_tokens: u32,
) -> Pin<Box<dyn Future<Output = Result<f64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn estimate_cost<'life0, 'async_trait>(
&'life0 self,
input_tokens: u32,
output_tokens: u32,
) -> Pin<Box<dyn Future<Output = Result<f64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Estimate cost for a request
Sourcefn metadata(&self) -> &ModelMetadata
fn metadata(&self) -> &ModelMetadata
Get model-specific metadata