| Crates.io | ollama-native |
| lib.rs | ollama-native |
| version | 1.0.2 |
| created_at | 2025-03-02 15:43:53.430982+00 |
| updated_at | 2025-03-04 13:06:52.211479+00 |
| description | A minimalist Ollama Rust SDK that provides the most basic functionality for interacting with Ollama |
| homepage | |
| repository | https://github.com/ZBcheng/ollama-native |
| max_upload_size | |
| id | 1574687 |
| size | 197,523 |
ollama-native is a minimalist Ollama Rust SDK that provides the most basic functionality for interacting with Ollama.
[!TIP] For users who need features like chat with history, these functionalities can be implemented at the business layer of your application (chat-with-history-example). Alternatively, you may choose to use other Ollama SDKs that provide these higher-level features.
cargo add ollama-native
use ollama_native::Ollama;
let ollama = Ollama::new("http://localhost:11434");
let response = ollama
.generate("llama3.1:8b")
.prompt("Tell me a joke about sharks")
.seed(5)
.temperature(3.2)
.await?;
Add stream feature:
cargo add ollama-native --features stream
use ollama_native::{Ollama, action::IntoStream};
use tokio::io::AsyncWriteExt;
use tokio_stream::StreamExt;
let ollama = Ollama::new("http://localhost:11434")
let mut stream = ollama
.generate("llama3.1:8b")
.prompt("Tell me a joke about sharks")
.stream()
.await?;
let mut out = tokio::io::stdout();
while let Some(Ok(item)) = stream.next().await {
out.write(item.response.as_bytes()).await?;
out.flush().await?;
}
[!TIP] See structured outputs example for more details.
// JSON mode
let resposne = ollama
.generate("llama3.1:8b")
.prompt("Ollama is 22 years old and is busy saving the world.")
.json() // Get the response in JSON format.
.await?;
let format = r#"
{
"type": "object",
"properties": {
"age": {
"type": "integer"
},
"available": {
"type": "boolean"
}
},
"required": [
"age",
"available"
]
}"#;
let resposne = ollama
.generate("llama3.1:8b")
.prompt("Ollama is 22 years old and is busy saving the world.")
.format(format)
.await?;
| ❌ | ✅ | |
|---|---|---|
| Chaining Methods |
|
|
| Fluent Response |
|
|
| Unified APIs |
|
|
This project is licensed under the MIT license.
Thanks mongodb for providing such an elegant design pattern.
Isabel Atkinson: “Rustify Your API: A Journey from Specification to Implementation” | RustConf 2024