Skip to main content

LanguageModel

Trait LanguageModel 

Source
pub trait LanguageModel:
    Send
    + Sync
    + Debug
    + Clone
    + 'static {
    // Required methods
    fn name(&self) -> String;
    fn generate_text<'life0, 'async_trait>(
        &'life0 mut self,
        options: LanguageModelOptions,
    ) -> Pin<Box<dyn Future<Output = Result<LanguageModelResponse, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn stream_text<'life0, 'async_trait>(
        &'life0 mut self,
        options: LanguageModelOptions,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Vec<LanguageModelStreamChunk>, Error>> + Send>>, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

The core trait abstracting the capabilities of a language model.

This trait is the foundation for all text-based AI interactions. Implementors of LanguageModel provide the necessary logic to connect to a specific model endpoint and perform operations. The trait is designed to be extensible to support various functionalities, such as single-shot generation and streaming responses.

Required Methods§

Source

fn name(&self) -> String

Returns the name or identifier of the language model.

This method provides a human-readable name for the model instance, which can be used for logging, debugging, or display purposes.

§Returns

A string representing the model’s name (e.g., “gpt-4”, “claude-3”).

Source

fn generate_text<'life0, 'async_trait>( &'life0 mut self, options: LanguageModelOptions, ) -> Pin<Box<dyn Future<Output = Result<LanguageModelResponse, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Performs a single, non-streaming text generation request.

This method sends a prompt to the model and returns the entire response at once.

§Errors

Returns an Error if the API call fails or the request is invalid.

Source

fn stream_text<'life0, 'async_trait>( &'life0 mut self, options: LanguageModelOptions, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Vec<LanguageModelStreamChunk>, Error>> + Send>>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Performs a streaming text generation request.

This method sends a prompt to the model and returns a stream of responses.

§Errors

Returns an Error if the API call fails or the request is invalid.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§