lc-chains 0.22.0

Chain compositions for langchainrust — LLMChain, SequentialChain, RetrievalQA, etc.
Documentation

Chain system for composing operations.

Chain is LangChain's core abstraction, representing a sequence of operations.

Core Concepts

  • BaseChain: Base trait for chains.
  • LLMChain: Most basic chain (Prompt + LLM).
  • SequentialChain: Execute multiple chains sequentially.

Example

use lc_chains::{LLMChain, SequentialChain};

let chain1 = LLMChain::new(llm.clone(), "Generate a word about {topic}");
let chain2 = LLMChain::new(llm, "Make a sentence with word: {word}");

let seq_chain = SequentialChain::new()
    .add_chain(Arc::new(chain1), vec!["topic"], vec!["word"])
    .add_chain(Arc::new(chain2), vec!["word"], vec!["sentence"]);

let inputs = HashMap::from([("topic".into(), "programming".into())]);
let result = seq_chain.invoke(inputs).await?;