pub trait LanguageModel: Send + Sync {
// Required methods
fn provider(&self) -> &str;
fn model_id(&self) -> &str;
fn do_generate<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, AiMuxError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn do_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<StreamResult, AiMuxError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn specification_version(&self) -> &'static str { ... }
fn retry_config(&self) -> RetryConfig { ... }
fn config_snapshot(&self) -> ProviderRecord { ... }
}Expand description
The unified language model trait (provider-facing).
Aligned with Vercel AI SDK LanguageModelV4.
§Implementation notes
do_generate/do_streamare not user-facing API. Users callgenerate_text/stream_text(free functions incrate::generate).- Providers must emit
StreamStartas the first stream part, andFinishas the last (before anyError). - Unsupported
CallOptionsfields must produce aWarning::Unsupportedrather than being silently dropped.
Required Methods§
Sourcefn do_generate<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, AiMuxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn do_generate<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, AiMuxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate a complete (non-streaming) response.
Sourcefn do_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<StreamResult, AiMuxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn do_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 CallOptions,
) -> Pin<Box<dyn Future<Output = Result<StreamResult, AiMuxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate a streaming response.
Provided Methods§
Sourcefn specification_version(&self) -> &'static str
fn specification_version(&self) -> &'static str
Specification version (always "v4").
Sourcefn retry_config(&self) -> RetryConfig
fn retry_config(&self) -> RetryConfig
Provider/model retry settings used when the caller does not override the retry count.
Sourcefn config_snapshot(&self) -> ProviderRecord
fn config_snapshot(&self) -> ProviderRecord
RFC-0023: 配置侧快照供录制。默认返回最小信息(provider/model_id); 各 provider 覆盖以提供 base_url/profile/api_key 来源等完整配置。 透明 decorator(TraceLayer 等)必须覆盖并转发 inner 快照。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".