Skip to main content

BaseLanguageModel

Trait BaseLanguageModel 

Source
pub trait BaseLanguageModel<Input: Send + Sync + 'static, Output: Send + Sync + 'static>: Runnable<Input, Output> {
    // Required methods
    fn model_name(&self) -> &str;
    fn get_num_tokens(&self, text: &str) -> usize;
    fn with_temperature(self, temp: f32) -> Self
       where Self: Sized;
    fn with_max_tokens(self, max: usize) -> Self
       where Self: Sized;

    // Provided methods
    fn temperature(&self) -> Option<f32> { ... }
    fn max_tokens(&self) -> Option<usize> { ... }
}
Expand description

Base trait for all language models.

All LLM wrappers inherit from this base class. It extends the Runnable interface for unified invocation.

Required Methods§

Source

fn model_name(&self) -> &str

Returns the model name.

Source

fn get_num_tokens(&self, text: &str) -> usize

Calculates token count for text.

§Arguments
  • text - Text to count tokens for.
§Returns

Token count.

Source

fn with_temperature(self, temp: f32) -> Self
where Self: Sized,

Sets the temperature parameter.

Source

fn with_max_tokens(self, max: usize) -> Self
where Self: Sized,

Sets the max tokens limit.

Provided Methods§

Source

fn temperature(&self) -> Option<f32>

Returns the temperature parameter.

Source

fn max_tokens(&self) -> Option<usize>

Returns the max tokens limit.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<E> BaseLanguageModel<Vec<Message>, LLMResult> for Box<dyn BaseChatModel<Error = E> + Send + Sync>
where E: Error + Send + Sync + 'static,

Source§

fn model_name(&self) -> &str

Source§

fn get_num_tokens(&self, text: &str) -> usize

Source§

fn temperature(&self) -> Option<f32>

Source§

fn max_tokens(&self) -> Option<usize>

Source§

fn with_temperature(self, _temp: f32) -> Self
where Self: Sized,

Source§

fn with_max_tokens(self, _max: usize) -> Self
where Self: Sized,

Implementors§