mlx-omni-server:基于 MLX 框架的本地 AI 推理服务器项目

MLX Omni Server is a local inference server powered by Apple's MLX framework, specifically designed for Apple Silicon (M-series) chips. It implements OpenAI-compatible API endpoints, enabling seamless integration with existing OpenAI SDK clients while leveraging the power of local ML inference.

分支10Tags24
文件最后提交记录最后更新时间
3 个月前
1 年前
1 年前
3 个月前
3 个月前
1 年前
1 年前
1 年前
1 年前
3 个月前
3 个月前

MLX Omni Server

针对 Apple Silicon 优化的本地 AI 推理服务器

PyPI 版本 Python 3.11+ 许可证:MIT 咨询 DeepWiki

MLX Omni Server 横幅

MLX Omni Server 提供与 OpenAIAnthropic API 的双重 API 兼容性,支持借助 MLX 框架在 Apple Silicon 上实现无缝的本地推理。

安装快速开始文档贡献

✨ 特性

  • 🚀 Apple Silicon 优化 - 基于 MLX 框架构建,适用于 M1/M2/M3/M4 芯片
  • 🔌 双重 API 支持 - 兼容 OpenAI 和 Anthropic API
  • 🎯 完整 AI 套件 - 聊天、音频处理、图像生成、嵌入
  • 高性能 - 具备硬件加速的本地推理
  • 🔐 隐私优先 - 所有处理均在您的设备本地进行
  • 🛠 即插即用替代 - 可与现有的 OpenAI 和 Anthropic SDK 配合使用

🚀 安装

pip install mlx-omni-server

⚡ 快速开始

  1. 启动服务器:

    mlx-omni-server
    
  2. 选择您偏好的 API:

    OpenAI API(点击展开)
    from openai import OpenAI
    
    client = OpenAI(
        base_url="http://localhost:10240/v1",
        api_key="not-needed"
    )
    
    response = client.chat.completions.create(
        model="mlx-community/gemma-3-1b-it-4bit-DWQ",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(response.choices[0].message.content)
    
    Anthropic API(点击展开)
    import anthropic
    
    client = anthropic.Anthropic(
        base_url="http://localhost:10240/anthropic",
        api_key="not-needed"
    )
    
    message = client.messages.create(
        model="mlx-community/gemma-3-1b-it-4bit-DWQ",
        max_tokens=1000,
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(message.content[0].text)
    

🎉 就是这么简单! 您现在已在 Mac 上本地运行 AI 了。

📋 API 支持

OpenAI 兼容端点 (/v1/*)

端点 功能 状态
/v1/chat/completions 工具对话、流式传输、结构化输出
/v1/audio/speech 文本转语音
/v1/audio/transcriptions 语音转文本
/v1/images/generations 图像生成
/v1/embeddings 文本嵌入
/v1/models 模型管理

Anthropic 兼容端点 (/anthropic/v1/*)

端点 功能 状态
/anthropic/v1/messages 工具消息、流式传输、思考模式
/anthropic/v1/models 带分页的模型列表

⚙️ 配置

# Default (port 10240)
mlx-omni-server

# Custom options
mlx-omni-server --port 8000
MLX_OMNI_LOG_LEVEL=debug mlx-omni-server

# View all options
mlx-omni-server --help

🛠 开发

开发环境设置
git clone https://github.com/madroidmaq/mlx-omni-server.git
cd mlx-omni-server
uv sync

# Start with hot-reload
uv run uvicorn mlx_omni_server.main:app --reload --host 0.0.0.0 --port 10240

测试:

uv run pytest                    # All tests
uv run pytest tests/chat/openai/ # OpenAI tests
uv run pytest tests/chat/anthropic/ # Anthropic tests

代码质量:

uv run black . && uv run isort . # Format code
uv run pre-commit run --all-files # Run hooks

🎯 核心功能

模型管理

  • 自动发现 HuggingFace 缓存中的 MLX 模型
  • 按需加载与智能缓存
  • 必要时自动下载模型

高级功能

  • 支持模型专用解析器的函数调用
  • 双 API 实时流式传输
  • JSON 模式验证与结构化输出
  • 支持模型的扩展推理(思维模式)

📚 文档

资源 说明
OpenAI API 指南 完整的 OpenAI API 参考
Anthropic API 指南 完整的 Anthropic API 参考
示例 实际使用示例

🔍 故障排除

常见问题

系统要求:

  • Python 3.11+
  • Apple Silicon 芯片 Mac(M1/M2/M3/M4)
  • 已安装 MLX 框架

快速修复:

# Check requirements
python --version  # Should be 3.11+
python -c "import mlx; print(mlx.__version__)"

# Pre-download models (if needed)
huggingface-cli download mlx-community/gemma-3-1b-it-4bit-DWQ

# Enable debug logging
MLX_OMNI_LOG_LEVEL=debug mlx-omni-server

🤝 贡献指南

贡献者快速设置:

git clone https://github.com/madroidmaq/mlx-omni-server.git
cd mlx-omni-server
uv sync && uv run pytest

🙏 致谢

基于 Apple 的 MLXFastAPI 以及 MLX-LM 构建

📄 许可证

MIT 许可证 • 与 OpenAI、Anthropic 或 Apple 无关联

🌟 星标历史

星标历史图表

项目介绍

MLX Omni Server is a local inference server powered by Apple's MLX framework, specifically designed for Apple Silicon (M-series) chips. It implements OpenAI-compatible API endpoints, enabling seamless integration with existing OpenAI SDK clients while leveraging the power of local ML inference.

定制我的领域