Skip to content

Commit f4183af

Browse files
authored
scripts : add --outdir option to hf.sh (ggml-org#6600)
* scripts : add --outdir option to hf.sh This commit adds an option to the hf.sh script that allows the user to specify an output directory for the downloaded file. The motivation for this changes is that examples that use the hf.sh script to download models from huggingface can now specify the output directory, perhaps to the `models` directory to keep them in one place and not clutter the root directory. Signed-off-by: Daniel Bevenius <[email protected]> * squash! scripts : add --outdir option to hf.sh Fix format of the --outdir option in the usage message. Signed-off-by: Daniel Bevenius <[email protected]> --------- Signed-off-by: Daniel Bevenius <[email protected]>
1 parent b804b1e commit f4183af

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

scripts/hf.sh

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Shortcut for downloading HF models
44
#
55
# Usage:
6-
# ./main -m $(./examples/hf.sh https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)
7-
# ./main -m $(./examples/hf.sh --url https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/blob/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)
8-
# ./main -m $(./examples/hf.sh --repo TheBloke/Mixtral-8x7B-v0.1-GGUF --file mixtral-8x7b-v0.1.Q4_K_M.gguf)
6+
# ./main -m $(./scripts/hf.sh https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q4_K_M.gguf)
7+
# ./main -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+
# ./main -m $(./scripts/hf.sh --repo TheBloke/Mixtral-8x7B-v0.1-GGUF --file mixtral-8x7b-v0.1.Q4_K_M.gguf)
99
#
1010

1111
# all logs go to stderr
@@ -14,7 +14,7 @@ function log {
1414
}
1515

1616
function usage {
17-
log "Usage: $0 [[--url] <url>] [--repo <repo>] [--file <file>] [-h|--help]"
17+
log "Usage: $0 [[--url] <url>] [--repo <repo>] [--file <file>] [--outdir <dir> [-h|--help]"
1818
exit 1
1919
}
2020

@@ -26,9 +26,9 @@ function has_cmd {
2626
}
2727

2828
if has_cmd wget; then
29-
cmd="wget -q --show-progress -c -O %s %s"
29+
cmd="wget -q --show-progress -c -O %s/%s %s"
3030
elif has_cmd curl; then
31-
cmd="curl -C - -f -o %s -L %s"
31+
cmd="curl -C - -f --output-dir %s -o %s -L %s"
3232
else
3333
log "[E] curl or wget not found"
3434
exit 1
@@ -37,6 +37,7 @@ fi
3737
url=""
3838
repo=""
3939
file=""
40+
outdir="."
4041

4142
# parse args
4243
while [[ $# -gt 0 ]]; do
@@ -53,6 +54,10 @@ while [[ $# -gt 0 ]]; do
5354
file="$2"
5455
shift 2
5556
;;
57+
--outdir)
58+
outdir="$2"
59+
shift 2
60+
;;
5661
-h|--help)
5762
usage
5863
;;
@@ -94,10 +99,10 @@ basename=$(basename $url)
9499
log "[+] attempting to download $basename"
95100

96101
if [ -n "$cmd" ]; then
97-
cmd=$(printf "$cmd" "$basename" "$url")
102+
cmd=$(printf "$cmd" "$outdir" "$basename" "$url")
98103
log "[+] $cmd"
99104
if $cmd; then
100-
echo $basename
105+
echo $outdir/$basename
101106
exit 0
102107
fi
103108
fi

0 commit comments

Comments
 (0)