query_stream_with_config

Function query_stream_with_config 

Source
pub async fn query_stream_with_config(
    prompt: &str,
    options: IFlowOptions,
) -> Result<impl Stream<Item = String>>
Expand description

Stream responses from iFlow with custom options

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
  • options - Configuration options for the query

§Returns

  • Ok(impl Stream<Item = String>) containing the response stream
  • Err(IFlowError) if there was an error

§Example

use iflow_cli_sdk_rust::{query_stream_with_config, IFlowOptions};
use futures::stream::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let options = IFlowOptions::new().with_timeout(60.0);
    let mut stream = query_stream_with_config("Tell me a story", options).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(())
}