Fix zsh compatibility and migrate from mlxserver to mlx-lm#10
Fix zsh compatibility and migrate from mlxserver to mlx-lm#10TinyTb wants to merge 2 commits intoPicoMLX:mainfrom
Conversation
This commit addresses two critical issues: 1. **Shell Compatibility**: Fixed Execute.command to support zsh users - Previously hardcoded `source ~/.bash_profile` which failed for zsh users - Now directly sources Conda initialization from common installation paths - Avoids Oh My Zsh errors when running from bash scripts - Supports multiple Conda distributions: miniforge, miniconda, anaconda 2. **MLX Server Migration**: Replaced deprecated mlxserver with mlx-lm - mlxserver (v0.1.14) is incompatible with current mlx-lm (v0.29.1) - mlxserver had ImportError: cannot import 'generate_step' from mlx_lm.utils - Migrated to mlx-lm's built-in server which is actively maintained - Updated Dependencies.plist for both Conda and pip platforms - Updated server.py to use 'python -m mlx_lm server' command - Maintains backward compatibility with existing model/port arguments Benefits: - Eliminates "No such file or directory" errors for zsh users - Fixes ImportError crashes when starting MLX servers - Uses officially supported and maintained MLX server implementation - Provides OpenAI-compatible API endpoints - No additional dependencies needed (mlx-lm includes server) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Summary of ChangesHello @TinyTb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness and compatibility of PicoMLXServer by addressing critical issues related to shell environments and the underlying MLX server implementation. It ensures a smoother experience for users, particularly those on zsh, and future-proofs the server by adopting the officially supported Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses two key issues: improving shell compatibility for zsh users by refining how Conda environments are sourced, and migrating from the deprecated mlxserver to the mlx-lm built-in server. The changes are well-implemented and align with the stated goals, enhancing the robustness and maintainability of the project. The migration to mlx-lm ensures the use of an actively maintained and officially supported server, which is a significant improvement.
| if [ -f "$HOME/miniforge3/etc/profile.d/conda.sh" ]; then | ||
| source "$HOME/miniforge3/etc/profile.d/conda.sh" | ||
| elif [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then | ||
| source "$HOME/miniconda3/etc/profile.d/conda.sh" | ||
| elif [ -f "$HOME/anaconda3/etc/profile.d/conda.sh" ]; then | ||
| source "$HOME/anaconda3/etc/profile.d/conda.sh" | ||
| elif [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then | ||
| source "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" |
There was a problem hiding this comment.
The current implementation relies on hardcoded paths for common Conda installations. While this covers many cases, it might be brittle if a user has a non-standard installation path or multiple Conda installations. Consider adding a fallback mechanism or a more dynamic way to locate the conda.sh script, or at least a comment indicating what happens if none of these paths are found (the script will proceed without Conda initialization, potentially leading to subsequent errors).
| subprocess.run([ | ||
| sys.executable, "-m", "mlx_lm", "server", | ||
| "--model", model_name, | ||
| "--port", str(port), | ||
| "--host", "127.0.0.1" | ||
| ]) |
There was a problem hiding this comment.
The subprocess.run call does not explicitly check for errors. If the mlx_lm server command fails to execute or encounters an internal error, the Python script will complete without indicating a failure to the calling process (e.g., the Swift application). Adding check=True to subprocess.run would raise a CalledProcessError if the command returns a non-zero exit code, making error detection more robust. Alternatively, you could capture stderr and check returncode manually.
| subprocess.run([ | |
| sys.executable, "-m", "mlx_lm", "server", | |
| "--model", model_name, | |
| "--port", str(port), | |
| "--host", "127.0.0.1" | |
| ]) | |
| subprocess.run( | |
| [ | |
| sys.executable, "-m", "mlx_lm", "server", | |
| "--model", model_name, | |
| "--port", str(port), | |
| "--host", "127.0.0.1" | |
| ], | |
| check=True # Add check=True to raise an error if the command fails | |
| ) |
| <key>installCommands</key> | ||
| <array> | ||
| <string>python3 pip install mlxserver</string> | ||
| <string>pip install mlx-lm</string> |
There was a problem hiding this comment.
The installCommands for mlx-lm under the pip installation section still includes python3 before pip install. While pip install mlx-lm should work directly if pip is in the PATH, removing python3 makes it consistent with typical pip usage within an activated environment and avoids potential issues if python3 points to a different interpreter than the one associated with pip.
<string>pip install mlx-lm</string>
Update documentation to reflect the migration from mlxserver to mlx-lm: - Updated API endpoint examples to use OpenAI-compatible endpoints - Changed curl examples from GET /generate to POST /v1/chat/completions - Added both chat completions and text completions examples - Updated links from mlxserver to mlx-lm repository - Updated acknowledgements to reference MLX team instead of mlxserver authors - Improved API endpoint documentation section The old /generate endpoint no longer exists in mlx-lm's server. Users should now use the standard OpenAI-compatible endpoints: - /v1/chat/completions (recommended for conversations) - /v1/completions (for simple text generation) - /v1/models (to list available models) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Summary
This PR addresses two critical issues affecting PicoMLXServer:
mlxserverwithmlx-lm's built-in serverProblem 1: Shell Compatibility Issues
Symptoms
No such file or directory: ~/.bash_profileOh My Zsh can't be loaded from: .errors when running bash scriptsconda: command not founderrorsRoot Cause
Execute.commandhardcodedsource ~/.bash_profile, which:~/.zshrc)Solution
Problem 2: MLX Server Compatibility
Symptoms
Root Cause
mlxserver(v0.1.14) is outdated and unmaintainedmlx-lm(v0.29.1) APIgenerate_stepfunction was removed/renamed in newer mlx-lm versionsSolution
mlx-lm's built-in server (actively maintained by Apple's MLX team)Dependencies.plistfor both Conda and pip installation pathsserver.pyto usepython -m mlx_lm servercommandBenefits
✅ Eliminates shell compatibility errors for zsh users
✅ Fixes ImportError crashes when starting MLX servers
✅ Uses officially supported and maintained MLX server
✅ Provides OpenAI-compatible API endpoints
✅ No additional dependencies (mlx-lm includes server)
✅ Future-proof against mlx-lm API changes
Files Changed
PicoMLXServer/Bash Commands/Execute.command- Conda initialization without shell configsPicoMLXServer/Setup/Models/Dependencies.plist- mlxserver → mlx-lm migrationPicoMLXServer/Server Manager/Models/server.py- Uses mlx-lm built-in serverTesting
Tested on macOS with:
Breaking Changes
None. The changes are backward compatible and maintain the same API surface.
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com