echodict/llama.cpp
version https://git-lfs.github.com/spec/v1 oid sha256:cfc44b7ba25614df70e6b65e3341cae0310163bd32fd31a6b928a542df433faf size 30786
0773
1#!/usr/bin/env bash2#3# Shortcut for downloading HF models4#5# Usage:6# ./llama-cli -m $(./scripts/hf.sh https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)7# ./llama-cli -m $(./scripts/hf.sh --url https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/blob/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)8# ./llama-cli -m $(./scripts/hf.sh --repo TheBloke/Mixtral-8x7B-v0.1-GGUF --file mixtral-8x7b-v0.1.Q4_K_M.gguf)9#10 11# all logs go to stderr12function log {13 echo "$@" 1>&214}15 16function usage {17 log "Usage: $0 [[--url] <url>] [--repo <repo>] [--file <file>] [--outdir <dir> [-h|--help]"18 exit 119}20 21# check for curl or wget22function has_cmd {23 if ! [ -x "$(command -v $1)" ]; then24 return 125 fi26}27 28if has_cmd wget; then29 cmd="wget -q -c -O %s/%s %s"30elif has_cmd curl; then31 cmd="curl -C - -f --output-dir %s -o %s -L %s"32else33 log "[E] curl or wget not found"34 exit 135fi36 37url=""38repo=""39file=""40outdir="."41 42# parse args43while [[ $# -gt 0 ]]; do44 case "$1" in45 --url)46 url="$2"47 shift 248 ;;49 --repo)50 repo="$2"51 shift 252 ;;53 --file)54 file="$2"55 shift 256 ;;57 --outdir)58 outdir="$2"59 shift 260 ;;61 -h|--help)62 usage63 ;;64 *)65 url="$1"66 shift67 ;;68 esac69done70 71if [ -n "$repo" ] && [ -n "$file" ]; then72 url="https://huggingface.co/$repo/resolve/main/$file"73fi74 75if [ -z "$url" ]; then76 log "[E] missing --url"77 usage78fi79 80# check if the URL is a HuggingFace model, and if so, try to download it81is_url=false82 83if [[ ${#url} -gt 22 ]]; then84 if [[ ${url:0:22} == "https://huggingface.co" ]]; then85 is_url=true86 fi87fi88 89if [ "$is_url" = false ]; then90 log "[E] invalid URL, must start with https://huggingface.co"91 exit 092fi93 94# replace "blob/main" with "resolve/main"95url=${url/blob\/main/resolve\/main}96 97basename=$(basename $url)98 99log "[+] attempting to download $basename"100 101if [ -n "$cmd" ]; then102 cmd=$(printf "$cmd" "$outdir" "$basename" "$url")103 log "[+] $cmd"104 if $cmd; then105 echo $outdir/$basename106 exit 0107 fi108fi109 110log "[-] failed to download"111 112exit 1113 