Skip to main content

lc_chains/
lib.rs

1// lc-chains/src/lib.rs
2//! Chain system for composing operations.
3//!
4//! Chain is LangChain's core abstraction, representing a sequence of operations.
5//!
6//! # Core Concepts
7//!
8//! - **BaseChain**: Base trait for chains.
9//! - **LLMChain**: Most basic chain (Prompt + LLM).
10//! - **SequentialChain**: Execute multiple chains sequentially.
11//!
12//! # Example
13//!
14//! ```ignore
15//! use lc_chains::{LLMChain, SequentialChain};
16//!
17//! let chain1 = LLMChain::new(llm.clone(), "Generate a word about {topic}");
18//! let chain2 = LLMChain::new(llm, "Make a sentence with word: {word}");
19//!
20//! let seq_chain = SequentialChain::new()
21//!     .add_chain(Arc::new(chain1), vec!["topic"], vec!["word"])
22//!     .add_chain(Arc::new(chain2), vec!["word"], vec!["sentence"]);
23//!
24//! let inputs = HashMap::from([("topic".into(), "programming".into())]);
25//! let result = seq_chain.invoke(inputs).await?;
26//! ```
27
28pub mod adapter;
29pub mod base;
30pub mod conversation_chain;
31pub mod conversation_retrieval;
32pub mod document_chains;
33pub mod llm_chain;
34pub mod retrieval_qa;
35pub mod router_chain;
36pub mod sequential_chain;
37
38pub use adapter::ChainRunnable;
39pub use base::{BaseChain, ChainError, ChainResult, ChainStream, StreamToken};
40pub use conversation_chain::{ConversationChain, ConversationChainBuilder};
41pub use conversation_retrieval::ConversationRetrievalChain;
42pub use document_chains::{
43    MapReduceDocumentsChain, MapRerankDocumentsChain, RefineDocumentsChain, StuffDocumentsChain,
44};
45pub use llm_chain::{LLMChain, LLMChainBuilder};
46pub use retrieval_qa::RetrievalQA;
47pub use router_chain::{LLMRouterChain, RouteDestination, RouterChain};
48pub use sequential_chain::SequentialChain;