Expand description
§Language Model
This crate provides a unified interface for language models. It supports streaming text, sampling, and embedding.
§Usage (with the kalosm-llama 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.complete(prompt);
print!("{prompt}");
while let Some(token) = result.next().await {
print!("{token}");
}
}
Re-exports§
pub use kalosm_sample;
Structs§
- Anthropic
Compatible Chat Model - An chat model that uses Anthropic’s API for the a remote chat model.
- Anthropic
Compatible Chat Model Builder - A builder for an Anthropic compatible chat model.
- Anthropic
Compatible Chat Session - A chat session for the Anthropic compatible chat model.
- Anthropic
Compatible Client - A client for making requests to an OpenAI compatible API.
- Boxed
Chat Constraints ForType - A constraints for
CreateDefaultChatConstraintsForType
that work with boxedStructuredChatModel
s. - Boxed
Chat Model - A boxed
ChatModel
. - Boxed
Chat Session - A boxed
ChatSession
. - Boxed
Completion Constraints ForType - A constraints for
CreateDefaultCompletionConstraintsForType
that work with boxedTextCompletionModel
s. - Boxed
Structured Chat Model - A boxed
StructuredChatModel
. - Boxed
Structured Text Completion Model - A boxed
BoxedStructuredTextCompletionModel
. - Boxed
Text Completion Model - A boxed
TextCompletionModel
. - Boxed
Text Completion Session - A boxed
TextCompletionSession
. - Cached
Embedding Model - Embedding models can be expensive to run. This struct wraps an embedding model with a cache that stores embeddings that have been computed before.
- Chat
Chat
is a chat interface that builds on top ofcrate::ChatModel
andcrate::StructuredChatModel
. It makes it easy to create a chat session with streaming responses, and constraints. Let’s start with a simple chat application:- Chat
Message - A single item in the chat history.
- Chat
Response Builder - A builder for a chat response. This is returned by
Chat::add_message
and can be modified until you start awaiting the response. - DynEmbedder
- A trait object for an embedder.
- Embedding
- Embeddings
- Embedding
Input - The input to an embedding model. This includes the text to be embedded and the type of embedding to output.
- Generation
Parameters - Parameters to use when generating text.
- NoAnthropicAPI
KeyError - An error that can occur when building a remote Anthropic model without an API key.
- NoConstraints
- A marker type that indicates that no constraints were supplied.
- NoOpenAIAPI
KeyError - An error that can occur when building a remote OpenAI model without an API key.
- OpenAI
Compatible Chat Model - An chat model that uses OpenAI’s API for the a remote chat model.
- OpenAI
Compatible Chat Model Builder - A builder for an openai compatible chat model.
- OpenAI
Compatible Chat Session - A chat session for the OpenAI compatible chat model.
- OpenAI
Compatible Client - A client for making requests to an OpenAI compatible API.
- OpenAI
Compatible Embedding Model - An embedder that uses OpenAI’s API for the a remote embedding model.
- OpenAI
Compatible Embedding Model Builder - A builder for an openai compatible embedding model.
- Schema
Parser - A parser for any type that implements the
Schema
trait andDeserialize
. - Task
- A task session lets you efficiently run a task with a model. The task session will reuse the model’s cache to avoid re-feeding the task prompt repeatedly.
- Text
Completion Builder - A builder for a text completion response. This is returned by
TextCompletionModelExt::complete
and can be modified withTextCompletionBuilder::with_sampler
andTextCompletionBuilder::with_constraints
until you start awaiting the response.
Enums§
- Anthropic
Compatible Chat Model Error - An error that can occur when running a
AnthropicCompatibleChatModel
. - Anthropic
Compatible Chat Response Error - An error that can occur when receiving a stream from the Anthropic API.
- Embedding
Variant - The type of embedding the model should output. For models that output different embeddings for queries and documents, this
- Message
Type - The type of a chat message
- OpenAI
Compatible Chat Model Error - An error that can occur when running a
OpenAICompatibleChatModel
. - OpenAI
Compatible Embedding Model Error - An error that can occur when running an
OpenAICompatibleEmbeddingModel
.
Traits§
- Chat
Model - A trait for unstructured chat models. This trait is required for any chat models
even if they do not support structured generation. While this trait is implemented for
all chat models, most methods to use models that implement this trait are implemented
in the
ChatModelExt
trait. - Chat
Model Ext - An extension trait for chat models with helpers for handling chat sessions. This trait is implemented automatically for all
crate::ChatModel
s. - Chat
Session - Chat Session
- Create
Chat Session - A trait for creating a chat session. While it the core trait
every chat session implementation implements, most methods to use models that implement
this trait are implemented in the
ChatModelExt
trait. - Create
Default Chat Constraints ForType - A trait that defines the default constraints for a type with this chat model.
- Create
Default Completion Constraints ForType - A trait that defines the default constraints for a type with this model.
- Create
Text Completion Session - A trait for creating a text completion session for a model. While it the core trait
every text completion model must implement, most methods to use models that implement
this trait are implemented in the
TextCompletionModelExt
trait. - Embedder
- 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.
- Embedder
Cache Ext - An extension trait for
Embedder
that allows for caching embeddings. - Embedder
Ext - An extension trait for
Embedder
with helper methods for iterators, and types that can be converted into a string. - Into
Chat Message - A trait for types that can be converted into a chat message.
- Into
Embedding - Convert a type into an embedding with an embedding model.
- Model
Builder - A builder that can create a model asynchronously.
- Model
Constraints - A type that can constrain the output of a model into a specific output type.
- Stream
Ext - An extension trait for
Stream
s that provides a variety of convenient combinator functions. - Structured
Chat Model - A trait for unstructured chat models that support structured generation. While this trait is implemented for
all structured chat models, most methods to use models that implement this trait are implemented
in the
ChatModelExt
trait. - Structured
Text Completion Model - A trait for text completion models that support structured generation. While this trait is implemented for
all structured text completion models, most methods to use models that implement this trait are implemented
in the
TextCompletionModelExt
trait. - Text
Completion Model - A trait for unstructured text completion models. This trait is required for any text completion models
even if they do not support structured generation. While this trait is implemented for all text completion models,
most methods to use models that implement this trait are implemented in the
TextCompletionModelExt
trait. - Text
Completion Model Ext - Text Completion Models
- Text
Completion Session - Text Completion Session
Functions§
- prompt_
input - A simple helper function for prompting the user for input.