2 releases

0.1.1 Feb 9, 2025
0.1.0 Feb 8, 2025

#140 in HTTP client

Download history 202/week @ 2025-02-04 49/week @ 2025-02-11

251 downloads per month

MIT license

120KB
280 lines


Logo

Rusty Ollama

A Rust client for the Ollama API
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Built With
  3. Getting Started
  4. Usage
  5. Roadmap
  6. Contributing
  7. License
  8. Contact
  9. Acknowledgments

About The Project

Rusty Ollama is a Rust client library for interacting with the Ollama API, providing both synchronous and streaming interfaces for working with large language models.

Features:

  • Simple API for text generation
  • Streaming responses for real-time processing
  • Context management for conversation history
  • Configurable request options
  • Error handling for API interactions

(back to top)

Built With

Rust Reqwest Tokio Serde

(back to top)

Getting Started

Prerequisites

Installation

Add to your Cargo.toml:

[dependencies]
rusty_ollama = { git = "0.1.1" }

Usage

Basic Generation

use rusty_ollama::{Ollama, OllamaError};

#[tokio::main]
async fn main() -> Result<(), OllamaError> {
    let mut ollama = Ollama::create_default()?;
    let response = ollama.generate("Why is the sky blue?").await?;
    println!("Response: {}", response.response);
    Ok(())
}

Streaming Responses

use rusty_ollama::{Ollama, OllamaError};
use futures::StreamExt;

#[tokio::main]
async fn main() -> Result<(), OllamaError> {
    let mut ollama = Ollama::create_default()?;
    let mut stream = ollama.stream_generate("Tell me a story about").await?;

    while let Some(response) = stream.next().await {
        match response {
            Ok(chunk) => print!("{}", chunk.response),
            Err(e) => eprintln!("Error: {}", e),
        }
    }

    Ok(())
}

for more examples see hte examples

(back to top)

Roadmap

  • Basic text generation
  • Streaming responses
  • Context management
  • Async trait implementations
  • Model management
  • Advanced configuration options (Modelfile)
  • Image processing
  • Comprehensive documentation
  • More error handling variants

See the open issues for full list of proposed features.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Top contributors

contrib.rocks image

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

lowpolycat1 - @acrylic_spark (discord)

Project Link: https://github.com/lowpolycat1/rusty_ollama

(back to top)

Acknowledgments

(back to top)

Dependencies

~7–19MB
~244K SLoC