bep/
lib.rs

1//! Bep is a Rust library for building LLM-powered applications that focuses on ergonomics and modularity.
2//!
3//! # Table of contents
4//! - [High-level features](#high-level-features)
5//! - [Simple Example](#simple-example)
6//! - [Core Concepts](#core-concepts)
7//! - [Integrations](#integrations)
8//!
9//! # High-level features
10//! - Full support for LLM completion and embedding workflows
11//! - Simple but powerful common abstractions over LLM providers (e.g. OpenAI, Cohere) and vector stores (e.g. MongoDB, in-memory)
12//! - Integrate LLMs in your app with minimal boilerplate
13//!
14//! # Simple example:
15//! ```
16//! use bep::{completion::Prompt, providers::openai};
17//!
18//! #[tokio::main]
19//! async fn main() {
20//!     // Create OpenAI client and agent.
21//!     // This requires the `OPENAI_API_KEY` environment variable to be set.
22//!     let openai_client = openai::Client::from_env();
23//!
24//!     let gpt4 = openai_client.agent("gpt-4").build();
25//!
26//!     // Prompt the model and print its response
27//!     let response = gpt4
28//!         .prompt("Who are you?")
29//!         .await
30//!         .expect("Failed to prompt GPT-4");
31//!
32//!     println!("GPT-4: {response}");
33//! }
34//! ```
35//! Note: using `#[tokio::main]` requires you enable tokio's `macros` and `rt-multi-thread` features
36//! or just `full` to enable all features (`cargo add tokio --features macros,rt-multi-thread`).
37//!
38//! # Core concepts
39//! ## Completion and embedding models
40//! Bep provides a consistent API for working with LLMs and embeddings. Specifically,
41//! each provider (e.g. OpenAI, Cohere) has a `Client` struct that can be used to initialize completion
42//! and embedding models. These models implement the [CompletionModel](crate::completion::CompletionModel)
43//! and [EmbeddingModel](crate::embeddings::EmbeddingModel) traits respectively, which provide a common,
44//! low-level interface for creating completion and embedding requests and executing them.
45//!
46//! ## Agents
47//! Bep also provides high-level abstractions over LLMs in the form of the [Agent](crate::agent::Agent) type.
48//!
49//! The [Agent](crate::agent::Agent) type can be used to create anything from simple agents that use vanilla models to full blown
50//! RAG systems that can be used to answer questions using a knowledge base.
51//!
52//! ## Vector stores and indexes
53//! Bep provides a common interface for working with vector stores and indexes. Specifically, the library
54//! provides the [VectorStoreIndex](crate::vector_store::VectorStoreIndex)
55//! trait, which can be implemented to define vector stores and indices respectively.
56//! Those can then be used as the knowledge base for a RAG enabled [Agent](crate::agent::Agent), or
57//! as a source of context documents in a custom architecture that use multiple LLMs or agents.
58//!
59//! # Integrations
60//! ## Model Providers
61//! Bep natively supports the following completion and embedding model provider integrations:
62//! - OpenAI
63//! - Cohere
64//! - Anthropic
65//! - Perplexity
66//! - Gemini
67//!
68//! You can also implement your own model provider integration by defining types that
69//! implement the [CompletionModel](crate::completion::CompletionModel) and [EmbeddingModel](crate::embeddings::EmbeddingModel) traits.
70//!
71//! ## Vector Stores
72//! Bep currently supports the following vector store integrations via companion crates:
73//! - `bep-mongodb`: Vector store implementation for MongoDB
74//! - `bep-lancedb`: Vector store implementation for LanceDB
75//! - `bep-neo4j`: Vector store implementation for Neo4j
76//! - `bep-qdrant`: Vector store implementation for Qdrant
77//!
78//! You can also implement your own vector store integration by defining types that
79//! implement the [VectorStoreIndex](crate::vector_store::VectorStoreIndex) trait.
80
81pub mod agent;
82pub mod cli_chatbot;
83pub mod completion;
84pub mod embeddings;
85pub mod extractor;
86pub(crate) mod json_utils;
87pub mod loaders;
88pub mod one_or_many;
89pub mod pipeline;
90pub mod providers;
91pub mod tool;
92pub mod vector_store;
93
94// Re-export commonly used types and traits
95pub use embeddings::Embed;
96pub use one_or_many::{EmptyListError, OneOrMany};
97
98#[cfg(feature = "derive")]
99pub use bep_derive::Embed;