Last active
May 12, 2026 08:07
-
-
Save g13n/25357ae2b587fa6b95caa8d5431a6f79 to your computer and use it in GitHub Desktop.
A simple friendly llama-cli executor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| usage_exit() { | |
| cat <<! | |
| usage: $0 -p path model | |
| The path to GGUF models can be the root/base path like \$HOME/.models or \$HOME/.cache/huggingface. | |
| The model name can be an unambiguous prefix like qwen-3-30b-a3b. | |
| Pass any flags to llama-cli through LLFLAGS: | |
| LLFLAGS="-ngl 99 -fa" llama-cpp -p ~/.cache/huggingface gemma-4 | |
| ! | |
| exit 1 | |
| } | |
| args=`getopt p: $*` | |
| if [ $? -ne 0 ]; then | |
| usage_exit $0 | |
| fi | |
| set -- $args | |
| while :; do | |
| case "$1" in | |
| -p) | |
| gguf_path="$2" | |
| shift; shift | |
| ;; | |
| --) | |
| shift; break | |
| ;; | |
| esac | |
| done | |
| if [ $# -ne 1 ]; then | |
| usage_exit $0 | |
| fi | |
| llama_cli=`type llama-cli` | |
| if [ $? -ne 0 ]; then | |
| echo 'llama-cli is not found in path' 1>&2 | |
| exit 2 | |
| fi | |
| llama_cli=`echo $llama_cli | cut -d' ' -f3` # path to llama-cli | |
| model=`echo $1 | tr A-Z a-z` | |
| nm=0 | |
| matches="" | |
| matched="" | |
| while read m; do | |
| m=`echo $m | tr A-Z a-z` | |
| r=`expr "$m" : ".*$model"` | |
| if [ $? -eq 0 ]; then | |
| nm=`expr 1 + $nm` | |
| matched=$m | |
| matches="$matches `basename $matched .gguf`" | |
| fi | |
| done < <(find $gguf_path -name '*.gguf' -print) | |
| if [ $nm -eq 0 ]; then | |
| echo "no models matched $model" 1>&2 | |
| exit 3 | |
| elif [ $nm -gt 1 ]; then | |
| echo "$model is ambiguous, multiple matches -$matches" 1>&2 | |
| exit 4 | |
| fi | |
| if [ -n "$LLFLAGS" ]; then | |
| llama_cli="$llama_cli $LLFLAGS" | |
| fi | |
| $llama_cli -m $matched |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment