Created
June 2, 2026 21:32
-
-
Save tkroo/41cbd0e327a0150ff7c1c4cf344e283c to your computer and use it in GitHub Desktop.
create llama-server command from hf cache list
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
| #!/bin/bash | |
| # Ensure the script exits if a command fails unexpectedly | |
| set -e | |
| # Fetch and process HuggingFace cache list in a single pipeline | |
| # awk filters for lines starting with 'model/', trims it, and prints the ID | |
| mapfile -t models < <(hf cache list --no-truncate 2>&1 | awk '/^model\// {sub(/^model\//, ""); print $1}') | |
| # Check if we actually found any models | |
| if [ ${#models[@]} -eq 0 ]; then | |
| echo "No models found in cache (or 'hf cache list' failed)." | |
| exit 1 | |
| fi | |
| echo "Available HuggingFace Models:" | |
| echo "----------------------------" | |
| # Use Bash's native 'select' to handle the menu UI and validation | |
| PS3="Enter the number of the model to use (or type Ctrl+C to quit): " | |
| select selected_model in "${models[@]}"; do | |
| if [ -n "$selected_model" ]; then | |
| break # Valid choice made, exit the menu loop | |
| else | |
| echo "Invalid selection. Please try again." | |
| fi | |
| done | |
| # Construct the initial command | |
| llama_server_command="llama-server --host 0.0.0.0 --port 8080 -hf \"$selected_model\"" | |
| # Allow user to edit the command interactively (-e enables Readline, -i pre-fills text) | |
| echo -e "\nReview or edit your execution command below:" | |
| read -e -i "$llama_server_command" final_command | |
| # Validate the final command structure before execution | |
| if [[ ! "$final_command" =~ ^llama-server.*--host.*--port.*-hf ]]; then | |
| echo "Error: Invalid command format. Command must start with:" | |
| echo " llama-server --host ... --port ... -hf ..." | |
| echo "" | |
| echo "Example allowed: llama-server --host 0.0.0.0 --port 8080 -hf <model-path>" | |
| exit 1 | |
| fi | |
| # Check for dangerous patterns (optional additional security) | |
| if [[ "$final_command" =~ (rm|cp|mv|wget|curl|nc|netcat|bash|sh\s+-i) ]]; then | |
| echo "Error: Dangerous command detected. Only llama-server execution allowed." | |
| exit 1 | |
| fi | |
| echo "Running: $final_command" | |
| bash -c "$final_command" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment