AI Model Wiki

    Skip to main content
    6 min read
    Lesson 4 of 5

    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:

    1. Prepare training data in JSONL format
    2. Upload to La Plateforme
    3. Configure hyperparameters (learning rate, epochs)
    4. Launch training job
    5. Deploy fine-tuned model to an endpoint

    Choosing the Right Model

    TaskRecommended Model
    Simple classification/extractionMistral Small
    General chat, summarizationMistral Small
    Complex reasoning, codingMistral Large
    Code generation specificallyCodestral
    Image + text tasksPixtral
    Budget self-hostedMixtral 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
    0 of 5 lessons marked complete

    Progress is kept in this browser only.