Skip to content

Commit 37afeaf

Browse files
authored
Merge pull request #531 from skylarbpayne/bump-mistral
Bump mistralai to > 1.0.0 in preparation for latest models such as Pixtral
2 parents 74bd210 + 47d85d7 commit 37afeaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+814
-420
lines changed

docs/WELCOME.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Make your first call to an LLM to extract the title and author of a book from th
8888
{% if provider == "Anthropic" %}
8989
```python hl_lines="19-38 43"
9090
{% elif provider == "Mistral" %}
91-
```python hl_lines="19-40 45"
91+
```python hl_lines="21-46 51"
9292
{% elif provider == "Gemini" %}
9393
```python hl_lines="19-57 62"
9494
{% elif provider == "Cohere" %}

docs/WHY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Let's compare structured outputs using Mirascope vs. the official SDKs:
9494
{% if provider == "Anthropic" %}
9595
```python hl_lines="19-38 43"
9696
{% elif provider == "Mistral" %}
97-
```python hl_lines="19-40 45"
97+
```python hl_lines="21-46 51"
9898
{% elif provider == "Gemini" %}
9999
```python hl_lines="19-57 62"
100100
{% elif provider == "Cohere" %}

docs/learn/async.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,14 @@ __Decorator Parameter:__
171171

172172
{% if provider == "LiteLLM" %}
173173
```python
174-
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
174+
{% elif provider in ["OpenAI", "Vertex AI"] %}
175175
```python hl_lines="2 5"
176176
{% elif provider == "Azure AI" %}
177177
```python hl_lines="1-2 8-10"
178178
{% elif provider == "Bedrock" %}
179179
```python hl_lines="7-10 14"
180+
{% elif provider == "Mistral" %}
181+
```python hl_lines="4 8"
180182
{% else %}
181183
```python hl_lines="1 5"
182184
{% endif %}
@@ -198,12 +200,14 @@ __Dynamic Configuration:__
198200

199201
{% if provider == "LiteLLM" %}
200202
```python
201-
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
203+
{% elif provider in ["OpenAI", "Vertex AI"] %}
202204
```python hl_lines="2 11"
203205
{% elif provider == "Azure AI" %}
204206
```python hl_lines="1-2 12-14"
205207
{% elif provider == "Bedrock" %}
206208
```python hl_lines="5-8 17"
209+
{% elif provider == "Mistral" %}
210+
```python hl_lines="4 15"
207211
{% else %}
208212
```python hl_lines="1 11"
209213
{% endif %}
@@ -217,12 +221,14 @@ __Dynamic Configuration:__
217221

218222
{% if provider == "LiteLLM" %}
219223
```python
220-
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
224+
{% elif provider in ["OpenAI", "Vertex AI"] %}
221225
```python hl_lines="2 9"
222226
{% elif provider == "Azure AI" %}
223227
```python hl_lines="1-2 10-12"
224228
{% elif provider == "Bedrock" %}
225229
```python hl_lines="5-8 15"
230+
{% elif provider == "Mistral" %}
231+
```python hl_lines="4 11"
226232
{% else %}
227233
```python hl_lines="1 9"
228234
{% endif %}

docs/learn/calls.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Let's take a look at a basic example using Mirascope vs. official provider SDKs:
5858
```python hl_lines="5-9"
5959
{% elif provider == "Azure AI" %}
6060
```python hl_lines="11-18"
61+
{% elif provider == "Mistral" %}
62+
```python hl_lines="10-15"
6163
{% else %}
6264
```python hl_lines="7-11"
6365
{% endif %}
@@ -360,12 +362,14 @@ You can pass a client to the `call` decorator using the `client` parameter:
360362

361363
{% if provider == "LiteLLM" %}
362364
```python
363-
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
365+
{% elif provider in ["OpenAI", "Vertex AI"] %}
364366
```python hl_lines="2 5"
365367
{% elif provider == "Azure AI" %}
366368
```python hl_lines="1-2 8-10"
367369
{% elif provider == "Bedrock" %}
368370
```python hl_lines="1 6"
371+
{% elif provider == "Mistral" %}
372+
```python hl_lines="4 8"
369373
{% else %}
370374
```python hl_lines="1 5"
371375
{% endif %}
@@ -393,6 +397,8 @@ You can also configure the client dynamically at runtime through the dynamic con
393397
```python hl_lines="1-2 12-14"
394398
{% elif provider == "Bedrock" %}
395399
```python hl_lines="1 11"
400+
{% elif provider == "Mistral" %}
401+
```python hl_lines="4 13"
396402
{% else %}
397403
```python hl_lines="2 11"
398404
{% endif %}
@@ -410,6 +416,8 @@ You can also configure the client dynamically at runtime through the dynamic con
410416
```python hl_lines="1-2 10-11"
411417
{% elif provider == "Bedrock" %}
412418
```python hl_lines="1 11"
419+
{% elif provider == "Mistral" %}
420+
```python hl_lines="4 11"
413421
{% else %}
414422
```python hl_lines="2 9"
415423
{% endif %}

docs/learn/response_models.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Let's take a look at a basic example using Mirascope vs. official provider SDKs:
4242
{% if provider == "Anthropic" %}
4343
```python hl_lines="19-38 43"
4444
{% elif provider == "Mistral" %}
45-
```python hl_lines="19-40 45"
45+
```python hl_lines="21-46 51"
4646
{% elif provider == "Gemini" %}
4747
```python hl_lines="19-57 62"
4848
{% elif provider == "Cohere" %}

docs/learn/tools.md

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Let's take a look at a basic example of each using Mirascope vs. official provid
9595
```python hl_lines="16-22 31-43 45-47"
9696
{% elif provider == "Vertex AI" %}
9797
```python hl_lines="6-12 18-34 36-43"
98+
{% elif provider == "Mistral" %}
99+
```python hl_lines="10-16 23-36 38-44"
98100
{% else %}
99101
```python hl_lines="8-14 21-34 36-38"
100102
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import os
2+
13
from mirascope.core import BaseMessageParam, mistral
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralAsyncClient())
7+
@mistral.call(
8+
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
9+
)
610
async def recommend_book_async(genre: str) -> list[BaseMessageParam]:
711
return [BaseMessageParam(role="user", content=f"Recommend a {genre} book")]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import os
2+
13
from mirascope.core import Messages, mistral
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralAsyncClient())
7+
@mistral.call(
8+
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
9+
)
610
async def recommend_book_async(genre: str) -> Messages.Type:
711
return Messages.User(f"Recommend a {genre} book")
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import os
2+
13
from mirascope.core import mistral
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralAsyncClient())
7+
@mistral.call(
8+
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
9+
)
610
async def recommend_book_async(genre: str) -> str:
711
return f"Recommend a {genre} book"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import os
2+
13
from mirascope.core import mistral, prompt_template
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralAsyncClient())
7+
@mistral.call(
8+
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
9+
)
610
@prompt_template("Recommend a {genre} book")
711
async def recommend_book_async(genre: str): ...
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import os
2+
13
from mirascope.core import BaseMessageParam, mistral
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

57
@mistral.call("mistral-large-latest")
6-
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
8+
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
79
return {
810
"messages": [
911
BaseMessageParam(role="user", content=f"Recommend a {genre} book")
1012
],
11-
"client": MistralAsyncClient(),
13+
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
1214
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import os
2+
13
from mirascope.core import Messages, mistral
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

57
@mistral.call("mistral-large-latest")
6-
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
8+
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
79
return {
810
"messages": [Messages.User(f"Recommend a {genre} book")],
9-
"client": MistralAsyncClient(),
11+
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
1012
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import os
2+
13
from mirascope.core import mistral, Messages
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

57
@mistral.call("mistral-large-latest")
6-
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
8+
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
79
return {
810
"messages": [Messages.User(f"Recommend a {genre} book")],
9-
"client": MistralAsyncClient(),
11+
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
1012
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import os
2+
13
from mirascope.core import mistral, prompt_template
2-
from mistralai.async_client import MistralAsyncClient
4+
from mistralai import Mistral
35

46

57
@mistral.call("mistral-large-latest")
68
@prompt_template("Recommend a {genre} book")
7-
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
9+
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
810
return {
9-
"client": MistralAsyncClient(),
11+
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
1012
}

examples/learn/calls/basic_usage/mistral/official_sdk_call.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
from mistralai.client import MistralClient
1+
import os
2+
from typing import cast
23

3-
client = MistralClient()
4+
from mistralai import Mistral
45

6+
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
57

6-
def recommend_book(genre: str) -> str:
7-
completion = client.chat(
8+
9+
def recommend_book(genre: str) -> str | None:
10+
completion = client.chat.complete(
811
model="mistral-large-latest",
912
messages=[{"role": "user", "content": f"Recommend a {genre} book"}],
1013
)
11-
return completion.choices[0].message.content
14+
if completion and (choices := completion.choices):
15+
return cast(str, choices[0].message.content)
1216

1317

1418
output = recommend_book("fantasy")
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
import os
2+
13
from mirascope.core import BaseMessageParam, mistral
2-
from mistralai.client import MistralClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralClient())
7+
@mistral.call(
8+
"mistral-large-latest",
9+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
10+
)
611
def recommend_book(genre: str) -> list[BaseMessageParam]:
712
return [BaseMessageParam(role="user", content=f"Recommend a {genre} book")]
13+
14+
15+
@mistral.call(
16+
"mistral-large-latest",
17+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
18+
)
19+
async def recommend_book_async(genre: str) -> list[BaseMessageParam]:
20+
return [BaseMessageParam(role="user", content=f"Recommend a {genre} book")]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
import os
2+
13
from mirascope.core import Messages, mistral
2-
from mistralai.client import MistralClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralClient())
7+
@mistral.call(
8+
"mistral-large-latest",
9+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
10+
)
611
def recommend_book(genre: str) -> Messages.Type:
712
return Messages.User(f"Recommend a {genre} book")
13+
14+
15+
@mistral.call(
16+
"mistral-large-latest",
17+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
18+
)
19+
async def recommend_book_async(genre: str) -> Messages.Type:
20+
return Messages.User(f"Recommend a {genre} book")
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
import os
2+
13
from mirascope.core import mistral
2-
from mistralai.client import MistralClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralClient())
7+
@mistral.call(
8+
"mistral-large-latest",
9+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
10+
)
611
def recommend_book(genre: str) -> str:
712
return f"Recommend a {genre} book"
13+
14+
15+
@mistral.call(
16+
"mistral-large-latest",
17+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
18+
)
19+
async def recommend_book_async(genre: str) -> str:
20+
return f"Recommend a {genre} book"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
import os
2+
13
from mirascope.core import mistral, prompt_template
2-
from mistralai.client import MistralClient
4+
from mistralai import Mistral
35

46

5-
@mistral.call("mistral-large-latest", client=MistralClient())
7+
@mistral.call(
8+
"mistral-large-latest",
9+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
10+
)
611
@prompt_template("Recommend a {genre} book")
712
def recommend_book(genre: str): ...
13+
14+
15+
@mistral.call(
16+
"mistral-large-latest",
17+
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
18+
)
19+
@prompt_template("Recommend a {genre} book")
20+
async def recommend_book_async(genre: str): ...
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import os
2+
13
from mirascope.core import BaseMessageParam, mistral
2-
from mistralai.client import MistralClient
4+
from mistralai import Mistral
35

46

57
@mistral.call("mistral-large-latest")
@@ -8,5 +10,5 @@ def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
810
"messages": [
911
BaseMessageParam(role="user", content=f"Recommend a {genre} book")
1012
],
11-
"client": MistralClient(),
13+
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
1214
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import os
2+
13
from mirascope.core import Messages, mistral
2-
from mistralai.client import MistralClient
4+
from mistralai import Mistral
35

46

57
@mistral.call("mistral-large-latest")
68
def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
79
return {
810
"messages": [Messages.User(f"Recommend a {genre} book")],
9-
"client": MistralClient(),
11+
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
1012
}

0 commit comments

Comments
 (0)