Minions 项目使用教程
minions Big & Small LLMs working together 项目地址: https://gitcode.com/gh_mirrors/minions/minions
1. 项目介绍
Minions 是一个通信协议,它使得小型设备上的模型能够与云端的前沿模型协作。通过仅在本地读取长上下文,我们可以在不降低或几乎不影响质量的情况下减少云端成本。本教程将指导您如何使用这个协议,并展示如何配置和运行项目。
2. 项目快速启动
环境准备
- 操作系统:Mac 或 Ubuntu
- Python 版本:3.10-3.11(Python 3.13 不受支持)
首先,创建一个虚拟环境(可选,使用您喜欢的包管理器,例如 conda 或 venv):
conda create -n minions python=3.11
克隆仓库并安装 Python 包
git clone https://github.com/HazyResearch/minions.git
cd minions
pip install -e .
如果需要安装可选的 MLX-LM,使用以下命令:
pip install -e ".[mlx]"
安装本地模型服务器
Minions 支持两种本地模型服务器:ollama 和 tokasaurus。至少安装其中一个。
- 对于没有 NVIDIA GPU 的用户,建议使用 ollama。按照这里的说明安装 ollama。如果启用了 Flash Attention,运行
launchctl setenv OLLAMA_FLASH_ATTENTION 1
并在 Mac 上重启 ollama 应用。 - 对于有 NVIDIA GPU 的用户,如果正在运行 Minions 协议,推荐使用 tokasaurus。使用以下命令安装 tokasaurus:
uv pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ tokasaurus==0.0.1.post1
设置 API 密钥
设置至少一个云端 LLM 提供商的 API 密钥。如果需要,创建一个 OpenAI API Key 或 TogetherAI API key 或 DeepSeek API key。
# OpenAI
export OPENAI_API_KEY=<your-openai-api-key>
export OPENAI_BASE_URL=<your-openai-base-url>
# Together AI
export TOGETHER_API_KEY=<your-together-api-key>
# OpenRouter
export OPENROUTER_API_KEY=<your-openrouter-api-key>
export OPENROUTER_BASE_URL=<your-openrouter-base-url>
# Perplexity
export PERPLEXITY_API_KEY=<your-perplexity-api-key>
export PERPLEXITY_BASE_URL=<your-perplexity-base-url>
# Tokasaurus
export TOKASAURUS_BASE_URL=<your-tokasaurus-base-url>
# DeepSeek
export DEEPSEEK_API_KEY=<your-deepseek-api-key>
运行演示应用
运行以下命令尝试 Minion 或 Minions 协议:
streamlit run app.py
如果遇到关于 ollama 客户端的错误,尝试运行以下命令:
OLLAMA_FLASH_ATTENTION=1 ollama serve
3. 应用案例和最佳实践
以下是一个使用 ollama 本地客户端和 openai 远程客户端的 Minion 协议示例:
from minions.clients.ollama import OllamaClient
from minions.clients.openai import OpenAIClient
from minions.minion import Minion
local_client = OllamaClient(model_name="llama3.2")
remote_client = OpenAIClient(model_name="gpt-4o")
# 实例化 Minion 对象
minion = Minion(local_client, remote_client)
context = """
Patient John Doe is a 60-year-old male with a history of hypertension. In his latest checkup, his blood pressure was recorded at 160/100 mmHg, and he reported occasional chest discomfort during physical activity.
Recent laboratory results show that his LDL cholesterol level is elevated at 170 mg/dL, while his HDL remains within the normal range at 45 mg/dL. Other metabolic indicators, including fasting glucose and renal function, are unremarkable.
"""
task = "Based on the patient's blood pressure and LDL cholesterol readings in the context, evaluate whether these factors together suggest an increased risk for cardiovascular complications."
# 执行 Minion 协议,最多两轮通信
output = minion(task=task, context=[context], max_rounds=2)
4. 典型生态项目
Minions 项目的生态系统中包括了多个相关项目,例如:
- ollama: 一个本地模型服务器,适用于没有 NVIDIA GPU 的用户。
- tokasaurus: 一个本地模型服务器,适用于有 NVIDIA GPU 的用户。
- Cartesia-MLX: 一个针对 Apple Silicon 优化的机器学习框架。
通过这些项目和工具的配合使用,可以更有效地利用 Minions 协议来提高模型协作的效率和性能。
minions Big & Small LLMs working together 项目地址: https://gitcode.com/gh_mirrors/minions/minions