MCPcopy Create free account
hub / github.com/NVIDIA-NeMo/Switchyard / stream

Method stream

crates/libsy/src/core/algorithm.rs:298–320  ·  view source on GitHub ↗

Transform the raw driver stream into a stream of [`Step`]s. Internal: the consumer stream is taken (once) by [`run_stream`](Algorithm::run_stream). A payload that does not match the expected type for its step becomes an `Err` item.

(&self)

Source from the content-addressed store, hash-verified

296 /// consumer stream is taken (once) by [`run_stream`](Algorithm::run_stream). A
297 /// payload that does not match the expected type for its step becomes an `Err` item.
298 pub(crate) fn stream(&self) -> impl Stream<Item = Result<Step>> + use<> {
299 self.driver.stream().map(|item| match item? {
300 DriverStep::Request(req) => Ok(Step::CallLlm(Box::new(CallLlmRequest::new(req)))),
301 DriverStep::Info(payload) => payload
302 .downcast::<Arc<dyn Decision>>()
303 .map(|decision| Step::Decision(*decision))
304 .map_err(|_| {
305 DriverError::TypeMismatch {
306 expected: "Arc<dyn Decision>",
307 }
308 .into()
309 }),
310 DriverStep::Done(payload) => payload
311 .downcast::<Response>()
312 .map(Step::ReturnToAgent)
313 .map_err(|_| {
314 DriverError::TypeMismatch {
315 expected: "Response",
316 }
317 .into()
318 }),
319 })
320 }
321}
322
323impl Default for Driver {

Callers 1

run_streamMethod · 0.45

Calls 2

DecisionInterface · 0.85
mapMethod · 0.45

Tested by

no test coverage detected