Building Applications with Mistral
From the course Mistral AI: European Open Models
Mistral models are well-suited for production applications. Here's how to build with them effectively.
Function Calling
Mistral Large supports robust function calling:
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}
}]
response = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
tools=tools,
tool_choice="auto"
)
JSON Mode
Force structured JSON output for reliable parsing:
response = client.chat.complete(
model="mistral-small-latest",
messages=[{"role": "user", "content": "List 3 French cities with population"}],
response_format={"type": "json_object"}
)
Fine-Tuning on La Plateforme
Mistral offers managed fine-tuning:
- Prepare training data in JSONL format
- Upload to La Plateforme
- Configure hyperparameters (learning rate, epochs)
- Launch training job
- Deploy fine-tuned model to an endpoint
Choosing the Right Model
| Task | Recommended Model |
|---|---|
| Simple classification/extraction | Mistral Small |
| General chat, summarization | Mistral Small |
| Complex reasoning, coding | Mistral Large |
| Code generation specifically | Codestral |
| Image + text tasks | Pixtral |
| Budget self-hosted | Mixtral 8x7B |
Common Pitfall: Not Passing tool_choice: "auto" for Optional Tool Use
When configuring function calling with Mistral, omitting tool_choice defaults to the model always calling a tool if one is available — even when a direct answer would be more appropriate. Set tool_choice: "auto" to let the model decide when tool use is necessary, and tool_choice: "none" to force a direct response. This mirrors OpenAI's behavior but must be set explicitly:
response = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": "What is 2 + 2?"}],
tools=tools,
tool_choice="auto" # Model decides — will likely answer directly here
)
Best Practice: Fine-Tune Mistral Small for Repetitive Classification Tasks
For high-volume, repetitive classification tasks (sentiment, intent detection, category tagging), fine-tuning Mistral Small is dramatically more cost-effective than prompting Mistral Large. A fine-tuned Mistral Small model can match or exceed Mistral Large's accuracy on a specific classification task at 10–20x lower per-request cost. Use La Plateforme's managed fine-tuning: prepare 500–2000 labeled examples in JSONL format, upload, train for 3–5 epochs, and deploy to a dedicated endpoint.
Named Product Reference: Codestral for Code Generation
Codestral (available as codestral-latest on La Plateforme) is Mistral's code-specialized model trained on 80+ programming languages with a 32K context window. It significantly outperforms Mistral Large on code completion, code explanation, and test generation tasks — while being faster and cheaper. For AI-powered IDE features, code review bots, or automated test generation pipelines, Codestral is the recommended choice over the general-purpose Mistral models. It also supports Fill-in-the-Middle (FIM) prompting for code completion use cases.
Key Takeaways
- •Mistral Large supports function calling and JSON mode for structured apps
- •La Plateforme offers managed fine-tuning with simple upload and deploy
- •Choose model by task: Small for efficiency, Large for complexity, Codestral for code
- •Mixtral is the best budget option for self-hosted applications
Progress is kept in this browser only.