pub async fn query_stream(prompt: &str) -> Result<impl Stream<Item = String>>Expand description
Stream responses from iFlow
Sends a query to iFlow and returns a stream of response chunks. This is useful for real-time output as the response is generated.
§Arguments
prompt- The query prompt to send to iFlow
§Returns
Ok(impl Stream<Item = String>)containing the response streamErr(IFlowError)if there was an error
§Example
use iflow_cli_sdk_rust::query_stream;
use futures::stream::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut stream = query_stream("Tell me a story").await?;
while let Some(chunk) = stream.next().await {
print!("{}", chunk);
// Flush stdout for real-time output
use std::io::{self, Write};
io::stdout().flush()?;
}
Ok(())
}