pub struct RunnableParallel<I: Send + Sync + 'static> { /* private fields */ }Expand description
A Runnable that runs multiple steps in parallel on the same input.
Each step is identified by a string key. The output is a
HashMap<String, Value> where each key maps to the corresponding
step’s output (serialized as serde_json::Value).
§Example
ⓘ
let parallel = RunnableParallel::<String>::new()
.with("length", RunnableLambda::new_sync(|s: String| s.len() as i64))
.with("upper", RunnableLambda::new_sync(|s: String| s.to_uppercase()));
let result = parallel.invoke("hello".to_string(), None).await?;
// result = {"length": 5, "upper": "HELLO"}Implementations§
Trait Implementations§
Source§impl<I: Clone + Send + Sync + 'static> Runnable<I, HashMap<String, Value>> for RunnableParallel<I>
impl<I: Clone + Send + Sync + 'static> Runnable<I, HashMap<String, Value>> for RunnableParallel<I>
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input: I,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: I,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute all steps in parallel using tokio tasks.
Source§fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<HashMap<String, Value>>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<HashMap<String, Value>>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Batch: each step processes all inputs independently.
Source§fn stream<'life0, 'async_trait>(
&'life0 self,
input: I,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<HashMap<String, Value>, LcelError>> + Send>>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
input: I,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<HashMap<String, Value>, LcelError>> + Send>>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream: invoke and return single-element stream.
Source§fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<Input, Self::Error>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Output, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<Input, Self::Error>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Output, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream-to-stream transformation - the core of LCEL streaming. Read more
Auto Trait Implementations§
impl<I> !RefUnwindSafe for RunnableParallel<I>
impl<I> !UnwindSafe for RunnableParallel<I>
impl<I> Freeze for RunnableParallel<I>
impl<I> Send for RunnableParallel<I>
impl<I> Sync for RunnableParallel<I>
impl<I> Unpin for RunnableParallel<I>
impl<I> UnsafeUnpin for RunnableParallel<I>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<I, O, R> RunnableExt<I, O> for R
impl<I, O, R> RunnableExt<I, O> for R
Source§fn pipe<O2, R2>(self, other: R2) -> RunnableSequence<Input, O2>
fn pipe<O2, R2>(self, other: R2) -> RunnableSequence<Input, O2>
Pipe the output of this runnable into another runnable. Read more
Source§fn into_sequence(self) -> RunnableSequence<Input, Output>
fn into_sequence(self) -> RunnableSequence<Input, Output>
Create a
RunnableSequence from this runnable as a single step. Read more