oxide-agent 0.1.0

Type-safe, high-performance Rust crate for building agentic systems on Ollama
Documentation
//! Zero-copy token-by-token streaming via `stream_chat`.
//!
//! Demonstrates how to consume the NDJSON stream yielded by Ollama and
//! print tokens to stdout as they arrive, with no buffering of the full
//! response body.
//!
//! Run with:
//!   cargo run --example streaming

use futures_util::StreamExt;
use oxide_agent::client::{HttpOllamaClient, OllamaClient};
use oxide_agent::types::{ChatRequest, Message, Role};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = HttpOllamaClient::new("http://localhost:11434");

    let req = ChatRequest {
        model: "llama3".into(),
        messages: vec![Message {
            role: Role::User,
            content: "Write a short haiku about the Rust programming language.".into(),
            tool_calls: None,
        }],
        tools: None,
        stream: true,
    };

    print!("Assistant: ");

    let mut stream = client.stream_chat(req);
    while let Some(result) = stream.next().await {
        let chunk = result?;
        print!("{}", chunk.message.content);

        // `done: true` signals the final chunk — flush and exit.
        if chunk.done {
            println!();
            break;
        }
    }

    Ok(())
}