Démarrage rapide¶
Option 1 : serveur compatible OpenAI¶
Démarrez le serveur :
# Simple mode - maximum throughput for single user
vllm-mlx serve mlx-community/Llama-3.2-3B-Instruct-4bit --port 8000
# Continuous batching - for multiple concurrent users
vllm-mlx serve mlx-community/Llama-3.2-3B-Instruct-4bit --port 8000 --continuous-batching
Utilisation avec le SDK Python OpenAI :
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
response = client.chat.completions.create(
model="mlx-community/Llama-3.2-3B-Instruct-4bit",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
Ou avec curl :
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "default", "messages": [{"role": "user", "content": "Hello!"}]}'
Option 2 : API Python directe¶
from vllm_mlx.models import MLXLanguageModel
model = MLXLanguageModel("mlx-community/Llama-3.2-3B-Instruct-4bit")
model.load()
# Generate text
output = model.generate("What is the capital of France?", max_tokens=100)
print(output.text)
# Streaming
for chunk in model.stream_generate("Tell me a story"):
print(chunk.text, end="", flush=True)
Option 3 : interface de chat Gradio¶
Ouvre une interface web à l'adresse http://localhost:7860
Modèles multimodaux¶
Pour la compréhension d'images et de vidéos, utilisez un modèle VLM :
response = client.chat.completions.create(
model="default",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}],
max_tokens=256
)
Modèles de raisonnement¶
Séparez le processus de réflexion du modèle de la réponse finale :
response = client.chat.completions.create(
model="default",
messages=[{"role": "user", "content": "What is 17 × 23?"}]
)
print(response.choices[0].message.content) # Final answer
Embeddings¶
Générez des embeddings textuels pour la recherche sémantique et le RAG :
vllm-mlx serve mlx-community/Qwen3-4B-4bit --embedding-model mlx-community/multilingual-e5-small-mlx
response = client.embeddings.create(
model="mlx-community/multilingual-e5-small-mlx",
input="Hello world"
)
Tool Calling¶
Activez l'appel de fonctions avec tout modèle compatible :
vllm-mlx serve mlx-community/Devstral-Small-2507-4bit \
--enable-auto-tool-choice --tool-call-parser mistral
Étapes suivantes¶
- Server Guide - Configuration complète du serveur
- Python API - Utilisation directe de l'API
- Multimodal Guide - Images et vidéos
- Audio Guide - Speech-to-Text et Text-to-Speech
- Embeddings Guide - Embeddings textuels
- Reasoning Models - Modèles de réflexion
- Tool Calling - Appel de fonctions
- Supported Models - Modèles disponibles