4 releases (2 breaking)

new 0.3.0 Feb 26, 2025
0.2.0 Feb 25, 2025
0.1.1 Feb 18, 2025
0.1.0 Jan 24, 2025

#359 in Unix APIs

Download history 81/week @ 2025-01-19 29/week @ 2025-01-26 8/week @ 2025-02-02

60 downloads per month

MIT license

22KB
284 lines

ollama_td License: MIT ollama_td on crates.io ollama_td on docs.rs

ollama_td : ollama tool download crate , which is a crate used exclusively to download the ollama command line tool or the binary itself ,

this is Not a crate to download the models, but to download the tool that is used to manage and download the models !!!

you can automate the download of the compressed (e.g. zip or tgz) CLI tool and

automatically unpack and place it where ever you want .

Breaking Changes

Ollama tool v5.8 and beyond changed ollama-darwin to ollama-darwin.tgz.

download_customize(o_download, f_stream) now accepts function to give you the ability to customize the process of downloading the tool.

otherwise , you can use the default implementation provided by the crate which is download(o_download).

Examples

Different platforms have different several options available .

Windows

you have three options :

  • ollama-windows-amd64.zip
  • ollama-windows-arm64.zip
  • OllamaSetup.exe
use ollama_td::*;
use reqwest::Response;
use std::fs::File;
use std::io::{Write, stdout};
use std::path::{Path, PathBuf};

#[tokio::main]
async fn main() -> OResult<()> {
    let d_location = Path::new(".");

    let down_x86 = o_d_x86(d_location).await?;
    let down_arm = o_d_arm(d_location).await?;
    let down_exe = o_d_exe(d_location).await?;

    assert_eq!(down_x86.to_str().unwrap(), "./ollama-windows-amd64.zip");
    assert_eq!(down_arm.to_str().unwrap(), "./ollama-windows-arm64.zip");
    assert_eq!(down_exe.to_str().unwrap(), "./OllamaSetup.exe");

    Ok(())
}

// general function function to be used among defferent other function examples !!
async fn download_ollama(
    d_location: &Path,
    platform: Platform,
    tag_version: TVersion,
) -> OResult<PathBuf> {
    let o_download = OllamaDownload::builder()?
        .platform(platform)
        .d_location(d_location)
        .tag_version(tag_version)
        .build()?;

    download_customize(o_download, download_custom_helper).await
}

// downloads [ollama-windows-amd64.zip]
async fn o_d_x86(d_location: &Path) -> OResult<PathBuf> {
    let platform = Platform::Windows(Windows::X86);
    download_ollama(d_location, platform, TVersion::Latest).await
}
// downloads [ollama-windows-arm64.zip]
async fn o_d_arm(d_location: &Path) -> OResult<PathBuf> {
    let platform = Platform::Windows(Windows::Arm);
    download_ollama(d_location, platform, TVersion::Tag("v0.5.7".to_string())).await
}

// downloads [OllamaSetup.exe]
async fn o_d_exe(d_location: &Path) -> OResult<PathBuf> {
    let platform = Platform::Windows(Windows::BinExe);
    download_ollama(d_location, platform, TVersion::Tag("v0.5.7".to_string())).await
}

// is used with download_custom function , here we stream to the disk storage and to the stdout!!
async fn download_custom_helper(mut res: Response, full_path: &mut Path) -> OResult<PathBuf> {
    let content_length = res.content_length().unwrap_or(1) as f64;
    let mut file = File::create(&full_path)?;
    let mut recived = 0.0;
    while let Some(c) = res.chunk().await? {
        recived += c.len() as f64;
        print!("\r{:.2}", (recived / content_length) * 100.0);
        file.write_all(&c)?;
        stdout().flush()?;
    }
    file.flush()?;
    Ok(full_path.to_path_buf())
}

Unix

you have two options :

  • ollama-darwin.tgz
  • Ollama-darwin.zip
use ollama_td::*;
use std::path::{Path, PathBuf};

#[tokio::main]
async fn main() -> OResult<()> {
   let d_location = Path::new(".");

   let o_d_bin = o_d_bin(d_location).await?;
   let o_d_zip = o_d_zip(d_location).await?;

   assert_eq!(o_d_bin.to_str().unwrap(), "./ollama-darwin.tgz");
   assert_eq!(o_d_zip.to_str().unwrap(), "./Ollama-darwin.zip");
   Ok(())
}

// this example attempts to download the ```ollama-darwin``` binary version !!!
async fn o_d_bin(d_location: &Path) -> OResult<PathBuf> {
   let u_bin = Platform::Unix(Unix::DarwinBin);

   let o_bin = OllamaDownload::builder()?
       .platform(u_bin)
       .tag_version(TVersion::Latest) //you can always set it to the latest version!!
       .d_location(d_location)
       .build()?;
   download(o_bin).await
}

// this example attempts to download the ```Ollama-darwin.zip``` CLI compressed version !!!
async fn o_d_zip(d_location: &Path) -> OResult<PathBuf> {
   let u_zip = Platform::Unix(Unix::DarwinZip);

   let o_zip = OllamaDownload::builder()?
       .platform(u_zip)
       .tag_version(TVersion::Tag("v0.5.7".to_owned())) // you can specify the tag version!!
       .d_location(d_location)
       .build()?;
   download(o_zip).await
}

Linux

you have five options :

  • ollama-linux-amd64.tgz
  • ollama-linux-amd64-rocm.tgz
  • ollama-linux-arm64.tgz
  • ollama-linux-arm64-jetpack5.tgz
  • ollama-linux-arm64-jetpack6.tgz
use ollama_td::*;
use std::path::{Path, PathBuf};

#[tokio::main]
async fn main() -> OResult<()> {
   let d_location = Path::new(".");

   let o_d_x86 = o_d_x86(d_location).await?;
   let o_d_x86_rocm = o_d_x86_rocm(d_location).await?;
   let o_d_arm = o_d_arm(d_location).await?;
   let o_d_arm_jet5 = o_d_arm_jet5(d_location).await?;
   let o_d_arm_jet6 = o_d_arm_jet6(d_location).await?;

   assert_eq!(o_d_x86.to_str().unwrap(), "./ollama-linux-amd64.tgz");

   assert_eq!(
       o_d_x86_rocm.to_str().unwrap(),
       "./ollama-linux-amd64-rocm.tgz"
   );

   assert_eq!(o_d_arm.to_str().unwrap(), "./ollama-linux-arm64.tgz");

   assert_eq!(
       o_d_arm_jet5.to_str().unwrap(),
       "./ollama-linux-arm64-jetpack5.tgz"
   );

   assert_eq!(
       o_d_arm_jet6.to_str().unwrap(),
       "./ollama-linux-arm64-jetpack6.tgz"
   );

   Ok(())
}

// general function to be reused among other functions!!
async fn download_ollama(d_location: &Path, platform: Platform) -> OResult<PathBuf> {
   let o_download = OllamaDownload::builder()?
       .platform(platform)
       .tag_version(TVersion::Latest)
       .d_location(d_location)
       .build()?;

   download(o_download).await
}

// downloads [ollama-linux-amd64.tgz]
async fn o_d_x86(d_location: &Path) -> OResult<PathBuf> {
   let platform = Platform::Linux(Linux::X86 { rocm: false });
   download_ollama(d_location, platform).await
}

// downloads [ollama-linux-amd64-rocm.tgz]
async fn o_d_x86_rocm(d_location: &Path) -> OResult<PathBuf> {
   let platform = Platform::Linux(Linux::X86 { rocm: true });
   download_ollama(d_location, platform).await
}

// downloads [ollama-linux-arm64.tgz]
async fn o_d_arm(d_location: &Path) -> OResult<PathBuf> {
   let platform = Platform::Linux(Linux::Arm(LinuxArm::Arm));
   download_ollama(d_location, platform).await
}
// downloads [ollama-linux-arm64-jetpack5.tgz]
async fn o_d_arm_jet5(d_location: &Path) -> OResult<PathBuf> {
   let platform = Platform::Linux(Linux::Arm(LinuxArm::Jetpack5));
   download_ollama(d_location, platform).await
}
// downloads [ollama-linux-arm64-jetpack6.tgz]
async fn o_d_arm_jet6(d_location: &Path) -> OResult<PathBuf> {
   let platform = Platform::Linux(Linux::Arm(LinuxArm::Jetpack6));
   download_ollama(d_location, platform).await
}

Dependencies

~12–26MB
~380K SLoC