pub struct ParallelChain { /* private fields */ }Expand description
A fan-out chain that runs multiple sub-chains concurrently and merges outputs.
Each branch receives the same input and runs in parallel via tokio. Their
outputs are stored under distinct keys in the result map.
Implementations§
Source§impl ParallelChain
impl ParallelChain
Sourcepub fn branch(
self,
chain: impl Chain + 'static,
output_key: impl Into<String>,
) -> Self
pub fn branch( self, chain: impl Chain + 'static, output_key: impl Into<String>, ) -> Self
Add a branch: run chain in parallel and store its output under output_key.
§Example
use rune_chain_parallel::ParallelChain;
use rune_chain_core::{Chain, ChainError, GenerateResult, PromptArgs};
use async_trait::async_trait;
struct Noop;
#[async_trait]
impl Chain for Noop {
async fn call(&self, _: PromptArgs) -> Result<GenerateResult, ChainError> {
Ok(GenerateResult::from_text(""))
}
}
let par = ParallelChain::new().branch(Noop, "a").branch(Noop, "b");
assert_eq!(par.output_keys(), vec!["a", "b", "generate_result"]);Trait Implementations§
Source§impl Chain for ParallelChain
impl Chain for ParallelChain
Source§fn call<'life0, 'async_trait>(
&'life0 self,
input: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn call<'life0, 'async_trait>(
&'life0 self,
input: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<GenerateResult, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run the chain and return the full
GenerateResult including token usage.Source§fn execute<'life0, 'async_trait>(
&'life0 self,
input: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
input: PromptArgs,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, ChainError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Run the chain and return a named-output map ready to pipe into the next step. Read more
Source§fn output_keys(&self) -> Vec<String>
fn output_keys(&self) -> Vec<String>
The keys this chain writes into the map returned by
Chain::execute.Source§fn input_keys(&self) -> Vec<String>
fn input_keys(&self) -> Vec<String>
The variable names this chain reads from its
PromptArgs input.Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input_variables: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<String, ChainError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input_variables: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<String, ChainError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Run the chain and return the generated text string only. Read more
Source§fn stream<'life0, 'async_trait>(
&'life0 self,
_input_variables: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamData, ChainError>> + Send>>, ChainError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
_input_variables: HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamData, ChainError>> + Send>>, ChainError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Stream tokens as they are produced rather than waiting for the full completion. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for ParallelChain
impl !UnwindSafe for ParallelChain
impl Freeze for ParallelChain
impl Send for ParallelChain
impl Sync for ParallelChain
impl Unpin for ParallelChain
impl UnsafeUnpin for ParallelChain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more