pydantic--pydantic-ai
9201ef759e
Harness Compat / harness compat (push) Failing after 0s
CI / test on 3.12 (standard) (push) Has been cancelled
CI / test on 3.13 (standard) (push) Has been cancelled
CI / test on 3.14 (standard) (push) Has been cancelled
CI / test on 3.10 (all-extras) (push) Has been cancelled
CI / test on 3.11 (all-extras) (push) Has been cancelled
CI / test on 3.12 (all-extras) (push) Has been cancelled
CI / test on 3.14 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.10 (pydantic-evals) (push) Has been cancelled
CI / test on 3.11 (pydantic-evals) (push) Has been cancelled
CI / test on 3.12 (pydantic-evals) (push) Has been cancelled
CI / deploy-docs-preview (push) Has been cancelled
CI / build release artifacts (push) Has been cancelled
CI / publish to PyPI (push) Has been cancelled
CI / Send tweet (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test on 3.10 (standard) (push) Has been cancelled
CI / test on 3.11 (standard) (push) Has been cancelled
CI / test on 3.13 (all-extras) (push) Has been cancelled
CI / test on 3.14 (all-extras) (push) Has been cancelled
CI / test on 3.10 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.11 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.12 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-evals) (push) Has been cancelled
CI / test on 3.14 (pydantic-evals) (push) Has been cancelled
CI / test on 3.10 (lowest-versions) (push) Has been cancelled
CI / test on 3.11 (lowest-versions) (push) Has been cancelled
CI / test on 3.12 (lowest-versions) (push) Has been cancelled
CI / test on 3.13 (lowest-versions) (push) Has been cancelled
CI / test on 3.14 (lowest-versions) (push) Has been cancelled
CI / test examples on 3.11 (push) Has been cancelled
CI / test examples on 3.12 (push) Has been cancelled
CI / test examples on 3.13 (push) Has been cancelled
CI / test examples on 3.14 (push) Has been cancelled
CI / coverage (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docs (push) Has been cancelled
78 行
1.9 KiB
Markdown
78 行
1.9 KiB
Markdown
# Mistral
|
|
|
|
## Install
|
|
|
|
To use `MistralModel`, you need to either install `pydantic-ai`, or install `pydantic-ai-slim` with the `mistral` optional group:
|
|
|
|
```bash
|
|
pip/uv-add "pydantic-ai-slim[mistral]"
|
|
```
|
|
|
|
## Configuration
|
|
|
|
To use [Mistral](https://mistral.ai) through their API, go to [console.mistral.ai/api-keys/](https://console.mistral.ai/api-keys/) and follow your nose until you find the place to generate an API key.
|
|
|
|
`LatestMistralModelNames` contains a list of the most popular Mistral models.
|
|
|
|
## Environment variable
|
|
|
|
Once you have the API key, you can set it as an environment variable:
|
|
|
|
```bash
|
|
export MISTRAL_API_KEY='your-api-key'
|
|
```
|
|
|
|
You can then use `MistralModel` by name:
|
|
|
|
```python
|
|
from pydantic_ai import Agent
|
|
|
|
agent = Agent('mistral:mistral-large-latest')
|
|
...
|
|
```
|
|
|
|
Or initialise the model directly with just the model name:
|
|
|
|
```python
|
|
from pydantic_ai import Agent
|
|
from pydantic_ai.models.mistral import MistralModel
|
|
|
|
model = MistralModel('mistral-small-latest')
|
|
agent = Agent(model)
|
|
...
|
|
```
|
|
|
|
## `provider` argument
|
|
|
|
You can provide a custom `Provider` via the `provider` argument:
|
|
|
|
```python
|
|
from pydantic_ai import Agent
|
|
from pydantic_ai.models.mistral import MistralModel
|
|
from pydantic_ai.providers.mistral import MistralProvider
|
|
|
|
model = MistralModel(
|
|
'mistral-large-latest', provider=MistralProvider(api_key='your-api-key', base_url='https://<mistral-provider-endpoint>')
|
|
)
|
|
agent = Agent(model)
|
|
...
|
|
```
|
|
|
|
You can also customize the provider with a custom `httpx.AsyncClient`:
|
|
|
|
```python
|
|
from httpx import AsyncClient
|
|
|
|
from pydantic_ai import Agent
|
|
from pydantic_ai.models.mistral import MistralModel
|
|
from pydantic_ai.providers.mistral import MistralProvider
|
|
|
|
custom_http_client = AsyncClient(timeout=30)
|
|
model = MistralModel(
|
|
'mistral-large-latest',
|
|
provider=MistralProvider(api_key='your-api-key', http_client=custom_http_client),
|
|
)
|
|
agent = Agent(model)
|
|
...
|
|
```
|