pub struct StreamMiddleware { /* private fields */ }Expand description
Intercepts the output stream from a wrapped StreamFn.
The inner StreamFn is called normally, then map_stream transforms
the resulting event stream before it reaches the consumer.
Implementations§
Source§impl StreamMiddleware
impl StreamMiddleware
Sourcepub fn new<F>(inner: Arc<dyn StreamFn>, f: F) -> Self
pub fn new<F>(inner: Arc<dyn StreamFn>, f: F) -> Self
Create a new middleware with a full stream transformation.
The closure receives the inner stream and returns a transformed stream.
Sourcepub fn with_logging<F>(inner: Arc<dyn StreamFn>, callback: F) -> Self
pub fn with_logging<F>(inner: Arc<dyn StreamFn>, callback: F) -> Self
Create a middleware that inspects each event via a logging callback.
Events pass through unmodified; the callback is called for each event.
Sourcepub fn with_map<F>(inner: Arc<dyn StreamFn>, f: F) -> Self
pub fn with_map<F>(inner: Arc<dyn StreamFn>, f: F) -> Self
Create a middleware that maps each event through a transformation.
Sourcepub fn with_filter<F>(inner: Arc<dyn StreamFn>, f: F) -> Self
pub fn with_filter<F>(inner: Arc<dyn StreamFn>, f: F) -> Self
Create a middleware that filters events based on a predicate.
Events for which the predicate returns false are dropped from the stream.
Trait Implementations§
Source§impl Debug for StreamMiddleware
impl Debug for StreamMiddleware
Source§impl StreamFn for StreamMiddleware
impl StreamFn for StreamMiddleware
Source§fn stream<'a>(
&'a self,
model: &'a ModelSpec,
context: &'a AgentContext,
options: &'a StreamOptions,
cancellation_token: CancellationToken,
) -> Pin<Box<dyn Stream<Item = AssistantMessageEvent> + Send + 'a>>
fn stream<'a>( &'a self, model: &'a ModelSpec, context: &'a AgentContext, options: &'a StreamOptions, cancellation_token: CancellationToken, ) -> Pin<Box<dyn Stream<Item = AssistantMessageEvent> + Send + 'a>>
Initiate a streaming LLM call. Read more
Auto Trait Implementations§
impl Freeze for StreamMiddleware
impl !RefUnwindSafe for StreamMiddleware
impl Send for StreamMiddleware
impl Sync for StreamMiddleware
impl Unpin for StreamMiddleware
impl UnsafeUnpin for StreamMiddleware
impl !UnwindSafe for StreamMiddleware
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