97e91a83f3
Ruff / Ruff (push) Has been cancelled
Test / Core Tests (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.10) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.11) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.12) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.13) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.9) (push) Has been cancelled
Test / Full Coverage (Python 3.11) (push) Has been cancelled
Test / Core Provider Tests (OpenAI) (push) Has been cancelled
Test / Core Provider Tests (Anthropic) (push) Has been cancelled
Test / Core Provider Tests (Google) (push) Has been cancelled
Test / Core Provider Tests (Other) (push) Has been cancelled
Test / Anthropic Tests (push) Has been cancelled
Test / Gemini Tests (push) Has been cancelled
Test / Google GenAI Tests (push) Has been cancelled
Test / Vertex AI Tests (push) Has been cancelled
Test / OpenAI Tests (push) Has been cancelled
Test / Writer Tests (push) Has been cancelled
Test / Auto Client Tests (push) Has been cancelled
ty / type-check (push) Has been cancelled
51 lines
1.2 KiB
Markdown
51 lines
1.2 KiB
Markdown
---
|
|
title: Using MistralAI for Structured Outputs
|
|
description: Learn how to use MistralAI models for inference, including setup, API key generation, and example code.
|
|
---
|
|
|
|
# Structured Outputs using Mistral
|
|
You can use MistralAI models for inference with Instructor using `from_provider`.
|
|
|
|
The examples use `mistral-large-latest`.
|
|
|
|
## MistralAI API
|
|
To use mistral you need to obtain a mistral API key.
|
|
Goto [mistralai](https://mistral.ai/) click on Build Now and login. Select API Keys from the left menu and then select
|
|
Create API key to create a new key.
|
|
|
|
## Use example
|
|
Some pip packages need to be installed to use the example:
|
|
```
|
|
pip install instructor mistralai pydantic
|
|
```
|
|
You need to export the mistral API key:
|
|
```
|
|
export MISTRAL_API_KEY=<your-api-key>
|
|
```
|
|
|
|
An example:
|
|
```python
|
|
import instructor
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class UserDetails(BaseModel):
|
|
name: str
|
|
age: int
|
|
|
|
|
|
# Using from_provider (recommended)
|
|
client = instructor.from_provider("mistral/mistral-large-latest")
|
|
|
|
resp = client.create(
|
|
response_model=UserDetails,
|
|
messages=[{"role": "user", "content": "Jason is 10"}],
|
|
temperature=0,
|
|
)
|
|
|
|
print(resp)
|
|
#> name='Jason' age=10
|
|
|
|
# output: UserDetails(name='Jason', age=10)
|
|
```
|