Crate kalosm_language_model
source ·Expand description
§Language Model
This crate provides a unified interface for language models. It supports streaming text, sampling, and embedding.
§Usage (with the RPhi implementation crate)
use kalosm::language::*;
#[tokio::main]
async fn main() {
let mut model = Llama::phi_3().await.unwrap();
let prompt = "The capital of France is ";
let mut result = model.stream_text(prompt).await.unwrap();
print!("{prompt}");
while let Some(token) = result.next().await {
print!("{token}");
}
}
Re-exports§
pub use kalosm_sample;
Structs§
- An embedder that uses OpenAI’s API for the Ada embedding model.
- A builder for the Ada embedder.
- The embedding space for the Ada embedding model.
- A type-erased session.
- Embedding models can be expensive to run. This struct wraps an embedding model with a cache that stores embeddings that have been computed before.
- The chat markers to use for the model.
- Embeddings
- The input to an embedding model. This includes the text to be embedded and the type of embedding to output.
- A builder for the
ModelExt::generate_text
method. - Parameters to use when generating text.
- A model that uses OpenAI’s API.
- A model that uses OpenAI’s API.
- A builder for gpt-3.5-turbo
- A builder for text-davinci-003
- A builder for the
ModelExt::stream_text
method. - The result of a structured parser stream.
- A marker type for models that do not support synchronous generation.
- This is a wrapper around a tokenizer to ensure that tokens can be returned to the user in a streaming way rather than having to wait for the full decoding.
- An untyped vector space that is not associated with a model. This can be used to erase the vector type from an embedding.
Enums§
- An error that can occur when loading or saving a cache.
- The type of embedding the model should output. For models that output different embeddings for queries and documents, this
- Feedback to give to the model when generating text.
Traits§
- An extension trait for models that can be converted into a trait object.
- A model that can be used to embed text. This trait is generic over the vector space that the model uses to help keep track of what embeddings came from which model.
- An extension trait for
Embedder
that allows for caching embeddings. - An extension trait for
Embedder
with helper methods for iterators, and types that can be converted into a string. - Convert a type into an embedding with an embedding model.
- Text Generation Models
- A builder that can create a model asynchronously.
- Text Generation Models
- A session for a model.
- An extension trait for
Stream
s that provides a variety of convenient combinator functions. - A raw interface for a model that can be used to generate text synchronously. This provides a very low level interface to a model’s session:
- An extension trait for sync models.
- The type of a vector space marks what model the vector space is from. You should only combine vector spaces that come from the same model.
Type Aliases§
- A trait object for a sync model.
- A trait object for an embedder.
- A trait object for a model.