Skip to main content

LanguageModel

Trait LanguageModel 

Source
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§

Source

fn provider_name(&self) -> &str

Provider name, e.g. “openai”, “anthropic”, etc.

Source

fn model_id(&self) -> &str

The upstream model ID, e.g. “gpt-4o”, “claude-3-5-sonnet-20241022”, etc.

Source

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.

Source

fn generate( &self, options: LanguageModelCallOptions, ) -> impl Future<Output = Result<LanguageModelGenerateResult>> + Send

Generates content based on the given options.

Source

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.

Implementations on Foreign Types§

Source§

impl<DYNOSAUR> LanguageModel for &DYNOSAUR
where DYNOSAUR: ?Sized + LanguageModel, Self: Send + Sync,

Source§

impl<DYNOSAUR> LanguageModel for &mut DYNOSAUR
where DYNOSAUR: ?Sized + LanguageModel, Self: Send + Sync,

Source§

impl<DYNOSAUR> LanguageModel for Box<DYNOSAUR>
where DYNOSAUR: ?Sized + LanguageModel, Self: Send + Sync,

Implementors§

Source§

impl LanguageModel for HookedModel

Source§

impl<'dynosaur_struct> LanguageModel for DynLanguageModel<'dynosaur_struct>