Trait kalosm_language::prelude::Model
source · pub trait Model: Send + Sync + 'static {
type TextStream: Stream<Item = String> + Send + Sync + Unpin + 'static;
type SyncModel: SyncModel;
// Required methods
fn tokenizer(&self) -> Arc<dyn Tokenizer + Sync + Send>;
fn stream_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
// Provided methods
fn run_sync_raw(
&self,
_f: Box<dyn for<'a> FnOnce(&'a mut Self::SyncModel) -> Pin<Box<dyn Future<Output = ()> + 'a>> + Send>
) -> Result<(), Error> { ... }
fn generate_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
max_tokens: Option<u32>,
stop_on: Option<&'life2 str>,
sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn generate_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn stream_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_prompt: &'life1 str,
_max_tokens: Option<u32>,
_stop_on: Option<&'life2 str>,
_sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
fn chat_markers(&self) -> Option<ChatMarkers> { ... }
}
Expand description
A model that can be used to generate text with an associated tokenizer.
The model may support using a custom sampler. If a specific model does not support a specific method, it will return an error.
Required Associated Types§
Required Methods§
sourcefn tokenizer(&self) -> Arc<dyn Tokenizer + Sync + Send>
fn tokenizer(&self) -> Arc<dyn Tokenizer + Sync + Send>
Get the tokenizer associated with this model to use for constrained generation.
sourcefn stream_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn stream_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Generate text with the given prompt.
See ModelExt::stream_text
for nicer API with an example.
Provided Methods§
sourcefn run_sync_raw(
&self,
_f: Box<dyn for<'a> FnOnce(&'a mut Self::SyncModel) -> Pin<Box<dyn Future<Output = ()> + 'a>> + Send>
) -> Result<(), Error>
fn run_sync_raw( &self, _f: Box<dyn for<'a> FnOnce(&'a mut Self::SyncModel) -> Pin<Box<dyn Future<Output = ()> + 'a>> + Send> ) -> Result<(), Error>
Run some code synchronously with the model.
See ModelExt::run_sync
for nicer API with an example.
sourcefn generate_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
max_tokens: Option<u32>,
stop_on: Option<&'life2 str>,
sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn generate_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
max_tokens: Option<u32>,
stop_on: Option<&'life2 str>,
sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Generate text with the given prompt.
sourcefn generate_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn generate_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Generate text with the given prompt.
See ModelExt::generate_text
for nicer API with an example.
sourcefn stream_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_prompt: &'life1 str,
_max_tokens: Option<u32>,
_stop_on: Option<&'life2 str>,
_sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn stream_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_prompt: &'life1 str,
_max_tokens: Option<u32>,
_stop_on: Option<&'life2 str>,
_sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Generate text with the given prompt.
sourcefn chat_markers(&self) -> Option<ChatMarkers>
fn chat_markers(&self) -> Option<ChatMarkers>
Returns the chat markers to use for the model if this is a chat model.
Trait Implementations§
source§impl Model for Box<dyn Model<SyncModel = Box<dyn SyncModel<Session = AnySession>>, TextStream = ChannelTextStream<String>> + Send>
impl Model for Box<dyn Model<SyncModel = Box<dyn SyncModel<Session = AnySession>>, TextStream = ChannelTextStream<String>> + Send>
§type TextStream = ChannelTextStream<String>
type TextStream = ChannelTextStream<String>
The type of stream that this model generates.
§type SyncModel = Box<dyn SyncModel<Session = AnySession>>
type SyncModel = Box<dyn SyncModel<Session = AnySession>>
The raw sync model that backs this model.
source§fn tokenizer(&self) -> Arc<dyn Tokenizer + Sync + Send>
fn tokenizer(&self) -> Arc<dyn Tokenizer + Sync + Send>
Get the tokenizer associated with this model to use for constrained generation.
source§fn stream_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<<Box<dyn Model<SyncModel = Box<dyn SyncModel<Session = AnySession>>, TextStream = ChannelTextStream<String>> + Send> as Model>::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Box<dyn Model<SyncModel = Box<dyn SyncModel<Session = AnySession>>, TextStream = ChannelTextStream<String>> + Send>: 'async_trait,
fn stream_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<<Box<dyn Model<SyncModel = Box<dyn SyncModel<Session = AnySession>>, TextStream = ChannelTextStream<String>> + Send> as Model>::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Box<dyn Model<SyncModel = Box<dyn SyncModel<Session = AnySession>>, TextStream = ChannelTextStream<String>> + Send>: 'async_trait,
Generate text with the given prompt. Read more
source§fn run_sync_raw(
&self,
_f: Box<dyn for<'a> FnOnce(&'a mut Self::SyncModel) -> Pin<Box<dyn Future<Output = ()> + 'a>> + Send>
) -> Result<(), Error>
fn run_sync_raw( &self, _f: Box<dyn for<'a> FnOnce(&'a mut Self::SyncModel) -> Pin<Box<dyn Future<Output = ()> + 'a>> + Send> ) -> Result<(), Error>
Run some code synchronously with the model. Read more
source§fn generate_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
max_tokens: Option<u32>,
stop_on: Option<&'life2 str>,
sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn generate_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
max_tokens: Option<u32>,
stop_on: Option<&'life2 str>,
sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Generate text with the given prompt.
source§fn generate_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn generate_text_inner<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 str,
parameters: GenerationParameters
) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Generate text with the given prompt. Read more
source§fn stream_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_prompt: &'life1 str,
_max_tokens: Option<u32>,
_stop_on: Option<&'life2 str>,
_sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn stream_text_with_sampler<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_prompt: &'life1 str,
_max_tokens: Option<u32>,
_stop_on: Option<&'life2 str>,
_sampler: Arc<Mutex<dyn Sampler>>
) -> Pin<Box<dyn Future<Output = Result<Self::TextStream, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Generate text with the given prompt.
source§fn chat_markers(&self) -> Option<ChatMarkers>
fn chat_markers(&self) -> Option<ChatMarkers>
Returns the chat markers to use for the model if this is a chat model.