Last active
August 18, 2025 21:07
-
-
Save moisoto/b256489d7039991093601d3b37a3c0db to your computer and use it in GitHub Desktop.
Script for using MLX-Chat as a UV Project
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
| # Check if uv is installed | |
| if ! command -v uv >/dev/null 2>&1; then | |
| echo "Error: uv is not installed or not in PATH" | |
| echo "Please install uv: https://docs.astral.sh/uv/getting-started/installation/" | |
| exit 1 | |
| fi | |
| PRJ="uv-mlx-chat" | |
| if [[ -d $PRJ ]] ; then | |
| echo "Project already exists" | |
| exit 1 | |
| fi | |
| uv init $PRJ | |
| if [ $? -eq 0 ]; then | |
| echo "Project $PRJ successfully created." | |
| else | |
| echo "Project $PRJ creation failed with exit code $?" | |
| exit 1 | |
| fi | |
| cd $PRJ | |
| # Create a Virtual Environment and activate it | |
| uv venv | |
| source .venv/bin/activate | |
| # Install MLX-LM | |
| uv add mlx-lm | |
| # Install HF | |
| uv add hf_transfer | |
| echo "HF_HUB_ENABLE_HF_TRANSFER=1" >> .env | |
| # Create Chat Script | |
| cat << EOF > chat.sh | |
| if [[ -z "\$1" ]] ; then | |
| MODEL="mlx-community/Qwen3-0.6B-8bit" | |
| echo "Defaulting to Model \$MODEL" | |
| else | |
| if [[ \$1 == "--list" ]] ; then | |
| echo "Here's a list of some nice models:" | |
| echo "----------------------------------" | |
| echo "mlx-community/Qwen3-0.6B-8bit (default model, very small and fast)" | |
| echo "mlx-community/gemma-3-270m-it-8bit" | |
| echo "mlx-community/gemma-3n-E4B-it-lm-4bit" | |
| echo "mlx-community/medgemma-4b-it-6bit" | |
| echo "mlx-community/codegemma-7b-it-8bit" | |
| echo "mlx-community/Meta-Llama-3-8B-Instruct-4bit" | |
| echo "mlx-community/Qwen2.5-Coder-14B-Instruct-4bit" | |
| echo | |
| echo "Your currently downloaded models are:" | |
| echo "-------------------------------------" | |
| ls -1 ~/.cache/huggingface/hub | sed 's/^models--//' | sed 's/--/\//g' | |
| echo | |
| echo "For more models please visit https://huggingface.co/mlx-community/collections" | |
| exit 0 | |
| else | |
| MODEL=\$1 | |
| fi | |
| fi | |
| source .venv/bin/activate | |
| export HF_HUB_ENABLE_HF_TRANSFER=1 | |
| # Start Chat | |
| mlx_lm.chat --model \$MODEL -m 10000 | |
| EOF | |
| # Give Permissions to script | |
| chmod 744 chat.sh | |
| echo "To list some nice models:" | |
| echo "cd $PRJ" | |
| echo "./chat.sh --list" | |
| echo | |
| echo "To chat, execute:" | |
| echo "cd $PRJ" | |
| echo "./chat.sh [MODEL]" | |
| echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment