Skip to content

Instantly share code, notes, and snippets.

@hizkifw
Created April 25, 2024 08:55
Show Gist options
  • Save hizkifw/5a50c1a7d463eabfd4612f0e040de80e to your computer and use it in GitHub Desktop.
Save hizkifw/5a50c1a7d463eabfd4612f0e040de80e to your computer and use it in GitHub Desktop.
Download gguf models from ollama's repository
#!/usr/bin/env bash
set -euo pipefail
model_name="$1"
if [[ -z "$model_name" ]]; then
echo "Usage: $0 <model_name>"
exit 1
fi
mkdir -p models
echo "Getting manifest for $model_name"
digest=$(curl -fsSL \
-H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
"https://registry.ollama.ai/v2/library/$model_name/manifests/latest" \
| jq -r '.layers[] | select(.mediaType == "application/vnd.ollama.image.model") | .digest')
dl_url="https://registry.ollama.ai/v2/library/$model_name/blobs/$digest"
out_fname="models/$model_name.gguf"
if [[ -f "$out_fname" ]]; then
echo "Verifying checksum"
hash=$(echo "$digest" | cut -d: -f2)
echo "$hash models/$model_name.gguf" | sha256sum -c > /dev/null && {
echo "$model_name is already downloaded"
exit 0
} || echo "Checksum verification failed, redownloading"
fi
echo "Downloading $model_name from $dl_url"
curl -L -H 'Accept: application/vnd.ollama.image.model' "$dl_url" -o "$out_fname"
echo "Verifying checksum"
hash=$(echo "$digest" | cut -d: -f2)
echo "$hash models/$model_name.gguf" | sha256sum -c
echo "Downloaded $model_name to $out_fname"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment