13 releases (8 stable)
new 1.0.7 | Feb 5, 2025 |
---|---|
1.0.5 | Feb 4, 2025 |
1.0.4 | Jan 27, 2025 |
0.1.1 | May 8, 2023 |
0.1.0 |
|
#62 in Machine learning
1,524 downloads per month
Used in 6 crates
140KB
3K
SLoC
LLM
Note: This crate name previously belonged to another project. The current implementation represents a new and different library. The previous crate is now archived and will not receive any updates. ref: https://github.com/rustformers/llm
LLM is a Rust library that lets you use multiple LLM backends in a single project: OpenAI, Anthropic (Claude), Ollama, DeepSeek, xAI, Phind, Groq and Google. With a unified API and builder style - similar to the Stripe experience - you can easily create chat or text completion requests without multiplying structures and crates.
Key Features
- Multi-backend: Manage OpenAI, Anthropic, Ollama, DeepSeek, xAI, Phind, Groq and Google through a single entry point.
- Multi-step chains: Create multi-step chains with different backends at each step.
- Templates: Use templates to create complex prompts with variables.
- Builder pattern: Configure your LLM (model, temperature, max_tokens, timeouts...) with a few simple calls.
- Chat & Completions: Two unified traits (
ChatProvider
andCompletionProvider
) to cover most use cases. - Extensible: Easily add new backends.
- Rust-friendly: Designed with clear traits, unified error handling, and conditional compilation via features.
- Validation: Add validation to your requests to ensure the output is what you expect.
- Evaluation: Add evaluation to your requests to score the output of LLMs.
- Function calling: Add function calling to your requests to use tools in your LLMs.
- REST API: Serve any LLM backend as a REST API with openai standard format.
Use any LLM backend on your project
Simply add LLM to your Cargo.toml
:
[dependencies]
llm = { version = "1.0.4", features = ["openai", "anthropic", "ollama", "deepseek", "xai", "phind", "google", "groq"] }
Serving any LLM backend as a REST API
- Use standard messages format
- Use step chains to chain multiple LLM backends together
- Expose the chain through a REST API with openai standard format
[dependencies]
llm = { version = "1.0.4", features = ["openai", "anthropic", "ollama", "deepseek", "xai", "phind", "google", "groq", "api"] }
More details in the api_example
More examples
Name | Description |
---|---|
anthropic_example |
Demonstrates integration with Anthropic's Claude model for chat completion |
chain_example |
Shows how to create multi-step prompt chains for exploring programming language features |
deepseek_example |
Basic DeepSeek chat completion example with deepseek-chat models |
embedding_example |
Basic embedding example with OpenAI's API |
multi_backend_example |
Illustrates chaining multiple LLM backends (OpenAI, Anthropic, DeepSeek) together in a single workflow |
ollama_example |
Example of using local LLMs through Ollama integration |
openai_example |
Basic OpenAI chat completion example with GPT models |
phind_example |
Basic Phind chat completion example with Phind-70B model |
validator_example |
Basic validator example with Anthropic's Claude model |
xai_example |
Basic xAI chat completion example with Grok models |
evaluation_example |
Basic evaluation example with Anthropic, Phind and DeepSeek |
google_example |
Basic Google Gemini chat completion example with Gemini models |
google_embedding_example |
Basic Google Gemini embedding example with Gemini models |
tool_calling_example |
Basic tool calling example with OpenAI |
deepclaude_pipeline_example |
Basic deepclaude pipeline example with DeepSeek and Claude |
api_example |
Basic API (openai standard format) example with OpenAI, Anthropic, DeepSeek and Groq |
api_deepclaude_example |
Basic API (openai standard format) example with DeepSeek and Claude |
Usage
Here's a basic example using OpenAI for chat completion. See the examples directory for other backends (Anthropic, Ollama, DeepSeek, xAI, Google, Phind), embedding capabilities, and more advanced use cases.
Dependencies
~4–16MB
~209K SLoC