Skip to main content

query_stream

Function query_stream 

Source
pub async fn query_stream(prompt: &str) -> impl Stream<Item = Result<Message>>
Expand description

Run a one-shot query, yielding messages via a static boxed stream.

Collects the full response into a Vec and returns it wrapped in a tokio_stream::Stream. This avoids the lifetime problem of streaming directly from an owned Client without boxing the client.

For direct access to the underlying Vec, prefer query.

§Errors

Any connection or streaming error is emitted as the first Err item in the returned stream.

§Example

use tokio_stream::StreamExt as _;

#[tokio::main]
async fn main() -> gemini_cli_sdk::Result<()> {
    let stream = gemini_cli_sdk::query_stream("List five prime numbers").await;
    tokio::pin!(stream);
    while let Some(item) = stream.next().await {
        let msg = item?;
        if let Some(text) = msg.assistant_text() {
            print!("{text}");
        }
    }
    Ok(())
}