Streaming
Learn how to use the LlamaIndex workflow with streaming.
Workflow
API by default is designed for streaming data. In this guide, we will show you how to use the Workflow
API with streaming data.
Each workflow.run
call returns WorkflowContext
, which implements AsyncIterable
interface. You can use it to stream data.
We define a parallel computation workflow that computes the sum of numbers from 0 to total
.
The workflow sends ComputeEvent
events for each number and waits for ComputeResultEvent
events. After receiving all ComputeResultEvent
events, the workflow returns the sum as a StopEvent
.
What if we want cutoff if the sum exceeds a certain value?
Streaming
You can define more custom logic using AsyncIterable
interface.
For example. I just want to stop the workflow if I get a ComputeResultEvent
Streaming with UI
You can use the Workflow
API with UI libraries like React.
Last updated on