Skip to content

Commit 592a88c

Browse files
YanStesamuelcolvindmontagu
authored
Mistral Support (#173)
Co-authored-by: Samuel Colvin <[email protected]> Co-authored-by: David Montague <[email protected]>
1 parent 5dfee4e commit 592a88c

File tree

10 files changed

+2298
-7
lines changed

10 files changed

+2298
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ PydanticAI is a Python Agent Framework designed to make it less painful to build
3232
## Why use PydanticAI
3333

3434
* Built by the team behind Pydantic (the validation layer of the OpenAI SDK, the Anthropic SDK, LangChain, LlamaIndex, AutoGPT, Transformers, CrewAI, Instructor and many more)
35-
* Model-agnostic — currently OpenAI, Gemini, Anthropic, and Groq are supported. And there is a simple interface to implement support for other models.
35+
* Model-agnostic — currently OpenAI, Gemini, Anthropic, Groq, and Mistral are supported. And there is a simple interface to implement support for other models.
3636
* [Type-safe](https://ai.pydantic.dev/agents/#static-type-checking)
3737
* Control flow and agent composition is done with vanilla Python, allowing you to make use of the same Python development best practices you'd use in any other (non-AI) project
3838
* [Structured response](https://ai.pydantic.dev/results/#structured-result-validation) validation with Pydantic

docs/api/models/mistral.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `pydantic_ai.models.mistral`
2+
3+
::: pydantic_ai.models.mistral

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PydanticAI is a Python Agent Framework designed to make it less painful to build
1111
## Why use PydanticAI
1212

1313
* Built by the team behind Pydantic (the validation layer of the OpenAI SDK, the Anthropic SDK, LangChain, LlamaIndex, AutoGPT, Transformers, CrewAI, Instructor and many more)
14-
* Model-agnostic — currently OpenAI, Gemini, Anthropic, and Groq are supported, and there is a simple interface to implement support for other models.
14+
* Model-agnostic — currently OpenAI, Gemini, Anthropic, Groq, and Mistral are supported, and there is a simple interface to implement support for other models.
1515
* [Type-safe](agents.md#static-type-checking)
1616
* Control flow and agent composition is done with vanilla Python, allowing you to make use of the same Python development best practices you'd use in any other (non-AI) project
1717
* [Structured response](results.md#structured-result-validation) validation with Pydantic

mkdocs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ nav:
4040
- api/exceptions.md
4141
- api/settings.md
4242
- api/models/base.md
43-
- api/models/anthropic.md
4443
- api/models/openai.md
45-
- api/models/ollama.md
44+
- api/models/anthropic.md
4645
- api/models/gemini.md
4746
- api/models/vertexai.md
4847
- api/models/groq.md
48+
- api/models/mistral.md
49+
- api/models/ollama.md
4950
- api/models/test.md
5051
- api/models/function.md
5152

pydantic_ai_slim/pydantic_ai/models/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
'gemini-2.0-flash-exp',
5353
'vertexai:gemini-1.5-flash',
5454
'vertexai:gemini-1.5-pro',
55+
# since mistral models are supported by other providers (e.g. ollama), and some of their models (e.g. "codestral")
56+
# don't start with "mistral", we add the "mistral:" prefix to all to be explicit
57+
'mistral:mistral-small-latest',
58+
'mistral:mistral-large-latest',
59+
'mistral:codestral-latest',
60+
'mistral:mistral-moderation-latest',
5561
'ollama:codellama',
5662
'ollama:gemma',
5763
'ollama:gemma2',
@@ -280,6 +286,10 @@ def infer_model(model: Model | KnownModelName) -> Model:
280286
from .vertexai import VertexAIModel
281287

282288
return VertexAIModel(model[9:]) # pyright: ignore[reportArgumentType]
289+
elif model.startswith('mistral:'):
290+
from .mistral import MistralModel
291+
292+
return MistralModel(model[8:])
283293
elif model.startswith('ollama:'):
284294
from .ollama import OllamaModel
285295

0 commit comments

Comments
 (0)