Skip to main content

lc_core/language_models/
base.rs

1// src/core/language_models/base.rs
2//! Language model base trait.
3
4use crate::runnables::Runnable;
5use async_trait::async_trait;
6
7/// Base trait for all language models.
8///
9/// All LLM wrappers inherit from this base class.
10/// It extends the Runnable interface for unified invocation.
11#[async_trait]
12pub trait BaseLanguageModel<Input: Send + Sync + 'static, Output: Send + Sync + 'static>:
13    Runnable<Input, Output>
14{
15    /// Returns the model name.
16    fn model_name(&self) -> &str;
17
18    /// Calculates token count for text.
19    ///
20    /// # Arguments
21    /// * `text` - Text to count tokens for.
22    ///
23    /// # Returns
24    /// Token count.
25    fn get_num_tokens(&self, text: &str) -> usize;
26
27    /// Returns the temperature parameter.
28    fn temperature(&self) -> Option<f32> {
29        None
30    }
31
32    /// Returns the max tokens limit.
33    fn max_tokens(&self) -> Option<usize> {
34        None
35    }
36
37    /// Sets the temperature parameter.
38    fn with_temperature(self, temp: f32) -> Self
39    where
40        Self: Sized;
41
42    /// Sets the max tokens limit.
43    fn with_max_tokens(self, max: usize) -> Self
44    where
45        Self: Sized;
46}