Expand description
A module for implementing a sequential chain of LLM steps.
This module provides the Chain
struct, which represents a sequential chain of steps for Large Language Models (LLMs). Each step in the chain is executed in order, and the output of the previous step is available as input to the next step.
The Chain
struct allows you to:
- Create a new chain with a vector of
Step
instances - Execute the chain with a given set of
Parameters
and anExecutor
The Chain
struct is designed to work with any executor that implements the Executor
trait, providing flexibility and extensibility.
§Example
ⓘ
// Assuming an executor `executor` that implements the `Executor` trait.
let step1 = Step::new(prompt!("Write a summary for this text: {{text}}"));
let step2 = Step::new(prompt!("{{text}}\n\nWrite a tweet thread for the above summary");
let chain = Chain::new(vec![step1, step2]);
let parameters = parameters!("your input text here")
// Execute the chain with the provided parameters and executor.
let result = chain.run(parameters, &executor).await;
This module also provides serialization and deserialization support for the Chain
struct, allowing you to store and load chains using formats like JSON, YAML, or others.
Structs§
- Chain
- A sequential chain is a chain where each step is executed in order, with the output of the previous step being available to the next step.
Enums§
- Sequential
Chain Error - The
SequentialChainError
enum represents errors that can occur when executing a sequential chain.