Skip to main content

LanguageModel

Trait LanguageModel 

Source
pub trait LanguageModel:
    Send
    + Sync
    + 'static {
    // Required methods
    fn provider(&self) -> &ProviderId;
    fn model_id(&self) -> &ModelId;
    fn supported_urls(&self) -> impl Future<Output = SupportedUrls> + Send;
    fn do_generate(
        &self,
        options: CallOptions,
    ) -> impl Future<Output = Result<GenerateResult, ProviderError>> + Send;
    fn do_stream(
        &self,
        options: CallOptions,
    ) -> impl Future<Output = Result<StreamResult, ProviderError>> + Send;
}
Expand description

A text generation model.

Implement this trait in a provider crate for every language model API. Implementations must be cheap to clone behind an Arc and safe to call concurrently. See the adapter contract in the provider specification: unsupported options produce warnings, tool input is passed through as raw JSON text, streams start with StreamStart and end with Finish or Error, and the cancellation token aborts the HTTP request.

Required Methods§

Source

fn provider(&self) -> &ProviderId

Provider identifier, for example openai.responses.

Source

fn model_id(&self) -> &ModelId

Model identifier as sent to the provider.

Source

fn supported_urls(&self) -> impl Future<Output = SupportedUrls> + Send

URL patterns (by media type) the provider can fetch itself.

Files whose URL does not match are downloaded by the core and inlined.

Source

fn do_generate( &self, options: CallOptions, ) -> impl Future<Output = Result<GenerateResult, ProviderError>> + Send

Generates a complete response.

Source

fn do_stream( &self, options: CallOptions, ) -> impl Future<Output = Result<StreamResult, ProviderError>> + Send

Generates a streamed response.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§