8 releases (3 stable)

new 1.0.2 Jan 16, 2025
1.0.1 Jan 15, 2025
0.1.1 May 8, 2023
0.1.0 Apr 12, 2023

#84 in Machine learning

Download history 70/week @ 2024-09-27 58/week @ 2024-10-04 82/week @ 2024-10-11 47/week @ 2024-10-18 34/week @ 2024-10-25 101/week @ 2024-11-01 11/week @ 2024-11-08 24/week @ 2024-11-15 46/week @ 2024-11-22 43/week @ 2024-11-29 66/week @ 2024-12-06 88/week @ 2024-12-13 40/week @ 2024-12-20 11/week @ 2024-12-27 37/week @ 2025-01-03 110/week @ 2025-01-10

210 downloads per month
Used in 6 crates

MIT license

100KB
2K 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 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 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 and CompletionProvider) 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.

Installation

Simply add LLM to your Cargo.toml:

[dependencies]
llm = { version = "1.0.1", features = ["openai", "anthropic", "ollama"] }

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

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–15MB
~196K SLoC