pub struct RunnableWithFallbacks<I: Send + Sync + 'static, O: Send + Sync + 'static> { /* private fields */ }Expand description
A Runnable that tries fallbacks when the primary fails.
If the primary runnable returns an error on invoke, each fallback is
tried in order. The first successful result is returned. If all fail,
the primary’s error is returned (so the user sees the error from
the runnable they explicitly chose).
The input type I must be Clone so that the input can be re-boxed
for each fallback attempt.
Implementations§
Trait Implementations§
Source§impl<I: Send + Sync + 'static, O: Send + Sync + 'static> Debug for RunnableWithFallbacks<I, O>
impl<I: Send + Sync + 'static, O: Send + Sync + 'static> Debug for RunnableWithFallbacks<I, O>
Source§impl<I: Clone + Send + Sync + 'static, O: Send + Sync + 'static> Runnable<I, O> for RunnableWithFallbacks<I, O>
impl<I: Clone + Send + Sync + 'static, O: Send + Sync + 'static> Runnable<I, O> for RunnableWithFallbacks<I, O>
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input: I,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<O, 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<O, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Try the primary, then fallbacks on failure.
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<O, 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<O, LcelError>> + Send>>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream: try the primary first. On failure, try fallbacks. Returns the first successful stream, or the primary’s error.
Source§fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<O>, 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<O>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Batch: apply fallback logic per-item.
Source§fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<I, LcelError>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<O, LcelError>> + Send + '_>>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn transform<'life0, 'async_trait>(
&'life0 self,
input: Pin<Box<dyn Stream<Item = Result<I, LcelError>> + Send>>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<O, LcelError>> + Send + '_>>, LcelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Transform: 逐项调用 invoke(带 fallback),产出与输入等长的流。
Source§fn batch_as_completed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<(usize, Output)>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn batch_as_completed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<(usize, Output)>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Batch processing that returns results in completion order. Read more
Auto Trait Implementations§
impl<I, O> !RefUnwindSafe for RunnableWithFallbacks<I, O>
impl<I, O> !UnwindSafe for RunnableWithFallbacks<I, O>
impl<I, O> Freeze for RunnableWithFallbacks<I, O>
impl<I, O> Send for RunnableWithFallbacks<I, O>
impl<I, O> Sync for RunnableWithFallbacks<I, O>
impl<I, O> Unpin for RunnableWithFallbacks<I, O>
impl<I, O> UnsafeUnpin for RunnableWithFallbacks<I, O>
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 moreSource§fn with_fallbacks<R>(
self,
fallbacks: Vec<R>,
) -> RunnableWithFallbacks<Input, Output>
fn with_fallbacks<R>( self, fallbacks: Vec<R>, ) -> RunnableWithFallbacks<Input, Output>
Add fallback runnables that are tried if this one fails. Read more
Source§fn with_retry(self, retry_config: RetryConfig) -> RunnableRetry<Input, Output>where
Input: Clone,
fn with_retry(self, retry_config: RetryConfig) -> RunnableRetry<Input, Output>where
Input: Clone,
Wrap this runnable with retry logic using exponential backoff. Read more
Source§fn configurable_alternatives<K, R>(
self,
which: impl Into<String>,
default_key: impl Into<String>,
alternatives: Vec<(K, R)>,
) -> RunnableConfigurable<Input, Output>
fn configurable_alternatives<K, R>( self, which: impl Into<String>, default_key: impl Into<String>, alternatives: Vec<(K, R)>, ) -> RunnableConfigurable<Input, Output>
Route between a default runnable and named alternatives at invoke time. Read more
Source§fn configurable_fields(self) -> RunnableConfigurableFields<Input, Output>
fn configurable_fields(self) -> RunnableConfigurableFields<Input, Output>
Override recognized config fields at invoke time from
config.configurable (Python’s Runnable.configurable_fields). Read moreSource§impl<I, R> RunnablePick<I> for R
impl<I, R> RunnablePick<I> for R
Source§fn pick<K>(
self,
keys: impl IntoIterator<Item = K>,
) -> RunnableSequence<I, HashMap<String, Value>>
fn pick<K>( self, keys: impl IntoIterator<Item = K>, ) -> RunnableSequence<I, HashMap<String, Value>>
Keep only the given keys of the dict output, dropping everything else. Read more