pub trait LanguageModel: Send + Sync {
// Required methods
fn provider_name(&self) -> &str;
fn model_id(&self) -> &str;
fn supported_urls(
&self,
) -> impl Future<Output = Record<String, Regex>> + Send;
fn generate(
&self,
options: LanguageModelCallOptions,
) -> impl Future<Output = Result<LanguageModelGenerateResult>> + Send;
fn stream(
&self,
options: LanguageModelCallOptions,
) -> impl Future<Output = Result<LanguageModelStreamResult>> + Send;
}Expand description
The main trait for a language model provider, which can generate content based on a prompt and options.
Each implementation represents a concrete upstream model instance (e.g. “gpt-4o via OpenAI chat completions”, “claude-3-5-sonnet via Anthropic messages”). The model ID is stored on the instance, not passed per-request.
Required Methods§
Sourcefn provider_name(&self) -> &str
fn provider_name(&self) -> &str
Provider name, e.g. “openai”, “anthropic”, etc.
Sourcefn model_id(&self) -> &str
fn model_id(&self) -> &str
The upstream model ID, e.g. “gpt-4o”, “claude-3-5-sonnet-20241022”, etc.
Sourcefn supported_urls(&self) -> impl Future<Output = Record<String, Regex>> + Send
fn supported_urls(&self) -> impl Future<Output = Record<String, Regex>> + Send
Media type -> Regex for supported URLs of that media type
Matched URLs are supported natively by the model and are not downloaded.
Sourcefn generate(
&self,
options: LanguageModelCallOptions,
) -> impl Future<Output = Result<LanguageModelGenerateResult>> + Send
fn generate( &self, options: LanguageModelCallOptions, ) -> impl Future<Output = Result<LanguageModelGenerateResult>> + Send
Generates content based on the given options.
Sourcefn stream(
&self,
options: LanguageModelCallOptions,
) -> impl Future<Output = Result<LanguageModelStreamResult>> + Send
fn stream( &self, options: LanguageModelCallOptions, ) -> impl Future<Output = Result<LanguageModelStreamResult>> + Send
Generates content based on the given options, but returns a stream of partial results.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.