kalosm_language_model/builder.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
use std::future::Future;
use kalosm_model_types::ModelLoadingProgress;
/// A builder that can create a model asynchronously.
///
/// # Example
/// ```rust, no_run
/// use kalosm::language::*;
///
/// #[tokio::main]
/// async fn main() {
/// let model = Llama::builder().start().await.unwrap();
/// }
/// ```
pub trait ModelBuilder {
/// The model that this trait creates.
type Model;
/// An error that can occur when creating the model.
type Error: Send + Sync + 'static;
/// Start the model.
fn start(self) -> impl Future<Output = Result<Self::Model, Self::Error>>
where
Self: Sized,
{
async { self.start_with_loading_handler(|_| {}).await }
}
/// Start the model with a loading handler.
fn start_with_loading_handler(
self,
handler: impl FnMut(ModelLoadingProgress) + Send + Sync + 'static,
) -> impl Future<Output = Result<Self::Model, Self::Error>>
where
Self: Sized;
/// Check if the model will need to be downloaded before use (default: false)
fn requires_download(&self) -> bool {
false
}
}