Skip to main content

Crate rune_chain_ollama

Crate rune_chain_ollama 

Source
Expand description

Ollama LLM provider for the rune-chain framework.

Implements Llm for a locally-running Ollama server. Any model you have pulled via ollama pull <model> is immediately usable. Defaults to http://localhost:11434 and the llama3.2 model.

§Features

  • Ollama — the client struct; configure once, call many times
  • Builder methods — base_url(), model(), temperature(), max_tokens()
  • generate() — returns the full response as GenerateResult with token usage
  • stream() — returns a Stream of StreamData chunks for real-time output
  • No API key required — Ollama runs locally

§Quick Start

use rune_chain_ollama::Ollama;
use rune_chain_core::{Llm, Message};

let llm = Ollama::new();  // localhost:11434, llama3.2

let result = llm.generate(&[
    Message::human("What is the capital of France?"),
]).await.unwrap();

println!("{}", result.generation);

Stream tokens as they arrive:

use rune_chain_ollama::Ollama;
use rune_chain_core::{Llm, Message};
use futures::StreamExt;

let llm = Ollama::new().model("mistral");
let mut stream = llm.stream(&[Message::human("Count to five.")]).await.unwrap();

while let Some(chunk) = stream.next().await {
    let data = chunk.unwrap();
    if data.is_finished { break; }
    print!("{}", data.content);
}

Structs§

Ollama
Ollama client implementing Llm.