pub struct RunnableGenerator<I: Send + 'static, O: Send + 'static> { /* private fields */ }Expand description
A runnable built from a generator function that yields streaming output.
The generator function receives an input and returns a Stream of results.
invoke() collects the entire stream into the final item, while stream()
returns the generator’s output directly for true streaming.
ⓘ
let gen = RunnableGenerator::new(|input: String| {
async_stream::stream! {
for ch in input.chars() {
yield Ok(ch.to_string());
}
}
});
// stream() yields individual characters; invoke() collects themImplementations§
Trait Implementations§
Source§impl<I: Send + 'static, O: Send + 'static> Runnable<I, Vec<O>> for RunnableGenerator<I, O>
impl<I: Send + 'static, O: Send + 'static> Runnable<I, Vec<O>> for RunnableGenerator<I, O>
Source§fn invoke<'life0, 'life1, 'async_trait>(
&'life0 self,
input: I,
_config: &'life1 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Vec<O>, SynapseError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn invoke<'life0, 'life1, 'async_trait>(
&'life0 self,
input: I,
_config: &'life1 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Vec<O>, SynapseError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute this runnable on a single input.
Source§fn stream<'a>(
&'a self,
input: I,
_config: &'a RunnableConfig,
) -> RunnableOutputStream<'a, Vec<O>>where
I: 'a,
fn stream<'a>(
&'a self,
input: I,
_config: &'a RunnableConfig,
) -> RunnableOutputStream<'a, Vec<O>>where
I: 'a,
Stream the output. Default wraps
invoke as a single-item stream.
Override for true streaming (e.g., token-by-token from an LLM).Source§fn batch<'life0, 'life1, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: &'life1 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Vec<Result<O, SynapseError>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn batch<'life0, 'life1, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: &'life1 RunnableConfig,
) -> Pin<Box<dyn Future<Output = Vec<Result<O, SynapseError>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute this runnable on multiple inputs sequentially.
Source§fn boxed(self) -> BoxRunnable<I, O>where
Self: Sized + 'static,
fn boxed(self) -> BoxRunnable<I, O>where
Self: Sized + 'static,
Wrap this runnable into a type-erased
BoxRunnable for composition via |.Auto Trait Implementations§
impl<I, O> Freeze for RunnableGenerator<I, O>
impl<I, O> !RefUnwindSafe for RunnableGenerator<I, O>
impl<I, O> Send for RunnableGenerator<I, O>
impl<I, O> Sync for RunnableGenerator<I, O>
impl<I, O> Unpin for RunnableGenerator<I, O>
impl<I, O> UnsafeUnpin for RunnableGenerator<I, O>
impl<I, O> !UnwindSafe for RunnableGenerator<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