Skip to content

Commit bcc7748

Browse files
github-actions[bot]speakeasybotamenasria
authored
chore: 🐝 Update SDK - Generate MISTRALAI MISTRALAI-SDK 1.5.0 (#184)
* ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.476.2 * [Feature] Structured Outputs * Add --no-root to CI's poetry install * Different CI fix * Fix CI * Rename schema_ to schema_definition * Set version to 1.5.0 --------- Co-authored-by: speakeasybot <[email protected]> Co-authored-by: Alexandre Menasria <[email protected]>
1 parent 77c7220 commit bcc7748

36 files changed

+901
-38
lines changed

.genignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pyproject.toml
2-
examples/*
2+
examples/*
3+
src/mistral/extra/*
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Linting Python custom files
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.12'
23+
24+
- name: Install ruff
25+
run: pip install ruff
26+
27+
- name: Lint with ruff
28+
# No need to lint the automatically generated Speakeasy code
29+
run: |
30+
ruff check examples/
31+
ruff check src/mistralai/_hooks/ --exclude __init__.py --exclude sdkhooks.py --exclude types.py
32+
ruff check src/mistralai/extra/
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Testing Python custom files
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
id: setup-python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.12'
24+
25+
- name: Install Poetry
26+
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
27+
with:
28+
virtualenvs-create: true
29+
virtualenvs-in-project: true
30+
virtualenvs-path: .venv
31+
installer-parallel: true
32+
33+
- name: Load cached venv
34+
id: cached-poetry-dependencies
35+
uses: actions/cache@v4
36+
with:
37+
path: .venv
38+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
39+
40+
- name: Install dependencies
41+
# Install dependencies if cache does not exist
42+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
43+
run: poetry install --no-interaction --no-root
44+
45+
- name: Run the 'src/mistralai/extra' package unit tests
46+
run: |
47+
source .venv/bin/activate
48+
python3.12 -m unittest discover -s src/mistralai/extra/tests -t src

.speakeasy/gen.lock

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
lockVersion: 2.0.0
22
id: 2d045ec7-2ebb-4f4d-ad25-40953b132161
33
management:
4-
docChecksum: dbfa566129ede53f4e3b2c91e81f6f74
4+
docChecksum: 553c31591e8dc33a58cb75f348c3aa72
55
docVersion: 0.0.2
6-
speakeasyVersion: 1.469.11
7-
generationVersion: 2.493.32
8-
releaseVersion: 1.4.0
9-
configChecksum: 46cde4e28fb5efba97051b54ac2e1c83
6+
speakeasyVersion: 1.477.0
7+
generationVersion: 2.497.0
8+
releaseVersion: 1.5.0
9+
configChecksum: 9a5649c5c372dc5fd2fde38a0faee40e
1010
repoURL: https://github.com/mistralai/client-python.git
1111
installationURL: https://github.com/mistralai/client-python.git
1212
published: true
1313
features:
1414
python:
1515
additionalDependencies: 1.0.0
1616
constsAndDefaults: 1.0.5
17-
core: 5.10.4
17+
core: 5.10.5
18+
customCodeRegions: 0.1.1
1819
defaultEnabledRetries: 0.2.0
1920
downloadStreams: 1.0.1
2021
enumUnions: 0.1.0
@@ -155,6 +156,7 @@ generatedFiles:
155156
- docs/models/jobsapiroutesfinetuningupdatefinetunedmodelrequest.md
156157
- docs/models/jobsout.md
157158
- docs/models/jobsoutobject.md
159+
- docs/models/jsonschema.md
158160
- docs/models/legacyjobmetadataout.md
159161
- docs/models/legacyjobmetadataoutobject.md
160162
- docs/models/listfilesout.md
@@ -319,6 +321,7 @@ generatedFiles:
319321
- src/mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py
320322
- src/mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py
321323
- src/mistralai/models/jobsout.py
324+
- src/mistralai/models/jsonschema.py
322325
- src/mistralai/models/legacyjobmetadataout.py
323326
- src/mistralai/models/listfilesout.py
324327
- src/mistralai/models/metricout.py
@@ -566,6 +569,7 @@ examples:
566569
responses:
567570
"422":
568571
application/json: {}
572+
"200": {}
569573
fim_completion_v1_fim_completions_post:
570574
speakeasy-default-fim-completion-v1-fim-completions-post:
571575
requestBody:
@@ -582,6 +586,7 @@ examples:
582586
responses:
583587
"422":
584588
application/json: {}
589+
"200": {}
585590
agents_completion_v1_agents_completions_post:
586591
speakeasy-default-agents-completion-v1-agents-completions-post:
587592
requestBody:
@@ -598,6 +603,7 @@ examples:
598603
responses:
599604
"422":
600605
application/json: {}
606+
"200": {}
601607
embeddings_v1_embeddings_post:
602608
speakeasy-default-embeddings-v1-embeddings-post:
603609
requestBody:

.speakeasy/gen.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ generation:
1313
oAuth2ClientCredentialsEnabled: true
1414
oAuth2PasswordEnabled: false
1515
python:
16-
version: 1.4.0
16+
version: 1.5.0
1717
additionalDependencies:
1818
dev:
1919
pytest: ^8.2.2
@@ -23,7 +23,7 @@ python:
2323
clientServerStatusCodesAsErrors: true
2424
defaultErrorName: SDKError
2525
description: Python Client SDK for the Mistral AI API.
26-
enableCustomCodeRegions: false
26+
enableCustomCodeRegions: true
2727
enumFormat: union
2828
envVarPrefix: MISTRAL
2929
fixFlags:

.speakeasy/workflow.lock

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
speakeasyVersion: 1.469.11
1+
speakeasyVersion: 1.477.0
22
sources:
33
mistral-azure-source:
44
sourceNamespace: mistral-azure-source
@@ -14,11 +14,10 @@ sources:
1414
- latest
1515
mistral-openapi:
1616
sourceNamespace: mistral-openapi
17-
sourceRevisionDigest: sha256:c414dd5eecca5f02fe9012a1d131f696e0257fe100c371609272dbc6c522ef07
18-
sourceBlobDigest: sha256:f48af039106d00de84345fd095fbf4831f18fbeeef07e9ff7bba70a0e07eda07
17+
sourceRevisionDigest: sha256:af4a2854e017abc0ec9e4b557186611dcd69468d82d5ac7f81bfbe49165fc18d
18+
sourceBlobDigest: sha256:9f1bbc418fba3c7b5031bacdf9d431aff476fb4b2aa3838ed50fb3922563703c
1919
tags:
2020
- latest
21-
- speakeasy-sdk-regen-1737393201
2221
targets:
2322
mistralai-azure-sdk:
2423
source: mistral-azure-source
@@ -37,10 +36,10 @@ targets:
3736
mistralai-sdk:
3837
source: mistral-openapi
3938
sourceNamespace: mistral-openapi
40-
sourceRevisionDigest: sha256:c414dd5eecca5f02fe9012a1d131f696e0257fe100c371609272dbc6c522ef07
41-
sourceBlobDigest: sha256:f48af039106d00de84345fd095fbf4831f18fbeeef07e9ff7bba70a0e07eda07
39+
sourceRevisionDigest: sha256:af4a2854e017abc0ec9e4b557186611dcd69468d82d5ac7f81bfbe49165fc18d
40+
sourceBlobDigest: sha256:9f1bbc418fba3c7b5031bacdf9d431aff476fb4b2aa3838ed50fb3922563703c
4241
codeSamplesNamespace: mistral-openapi-code-samples
43-
codeSamplesRevisionDigest: sha256:3f61d33c46733b24ecd422423900425b381529da038992e59bdb5a9b766bdf89
42+
codeSamplesRevisionDigest: sha256:cbf9b277d16c47816fc5d63b4c69cf0fbd1fe99d424c34ab465d2b61fcc6e5e8
4443
workflow:
4544
workflowVersion: 1.0.0
4645
speakeasyVersion: latest

.vscode/settings.json

-6
This file was deleted.

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
4242
* [Server Selection](#server-selection)
4343
* [Custom HTTP Client](#custom-http-client)
4444
* [Authentication](#authentication)
45+
* [Resource Management](#resource-management)
4546
* [Debugging](#debugging)
4647
* [IDE Support](#ide-support)
4748
* [Development](#development)
@@ -52,6 +53,11 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
5253
<!-- Start SDK Installation [installation] -->
5354
## SDK Installation
5455

56+
> [!NOTE]
57+
> **Python version upgrade policy**
58+
>
59+
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
60+
5561
The SDK can be installed with either *pip* or *poetry* package managers.
5662

5763
### PIP
@@ -754,6 +760,32 @@ with Mistral(
754760
```
755761
<!-- End Authentication [security] -->
756762

763+
<!-- Start Resource Management [resource-management] -->
764+
## Resource Management
765+
766+
The `Mistral` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
767+
768+
[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers
769+
770+
```python
771+
from mistralai import Mistral
772+
import os
773+
def main():
774+
with Mistral(
775+
api_key=os.getenv("MISTRAL_API_KEY", ""),
776+
) as mistral:
777+
# Rest of application here...
778+
779+
780+
# Or when using async:
781+
async def amain():
782+
async with Mistral(
783+
api_key=os.getenv("MISTRAL_API_KEY", ""),
784+
) as mistral:
785+
# Rest of application here...
786+
```
787+
<!-- End Resource Management [resource-management] -->
788+
757789
<!-- Start Debugging [debug] -->
758790
## Debugging
759791

RELEASES.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,14 @@ Based on:
148148
### Generated
149149
- [python v1.4.0] .
150150
### Releases
151-
- [PyPI v1.4.0] https://pypi.org/project/mistralai/1.4.0 - .
151+
- [PyPI v1.4.0] https://pypi.org/project/mistralai/1.4.0 - .
152+
153+
## 2025-01-27 13:57:39
154+
### Changes
155+
Based on:
156+
- OpenAPI Doc
157+
- Speakeasy CLI 1.476.2 (2.495.1) https://github.com/speakeasy-api/speakeasy
158+
### Generated
159+
- [python v1.5.0] .
160+
### Releases
161+
- [PyPI v1.5.0] https://pypi.org/project/mistralai/1.5.0 - .

docs/models/jsonschema.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# JSONSchema
2+
3+
4+
## Fields
5+
6+
| Field | Type | Required | Description |
7+
| ----------------------- | ----------------------- | ----------------------- | ----------------------- |
8+
| `name` | *str* | :heavy_check_mark: | N/A |
9+
| `schema_definition` | Dict[str, *Any*] | :heavy_check_mark: | N/A |
10+
| `description` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
11+
| `strict` | *Optional[bool]* | :heavy_minus_sign: | N/A |

docs/models/responseformat.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
| Field | Type | Required | Description |
77
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
8-
| `type` | [Optional[models.ResponseFormats]](../models/responseformats.md) | :heavy_minus_sign: | An object specifying the format that the model must output. Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. |
8+
| `type` | [Optional[models.ResponseFormats]](../models/responseformats.md) | :heavy_minus_sign: | An object specifying the format that the model must output. Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. |
9+
| `json_schema` | [OptionalNullable[models.JSONSchema]](../models/jsonschema.md) | :heavy_minus_sign: | N/A |

docs/models/responseformats.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ An object specifying the format that the model must output. Setting to `{ "type"
88
| Name | Value |
99
| ------------- | ------------- |
1010
| `TEXT` | text |
11-
| `JSON_OBJECT` | json_object |
11+
| `JSON_OBJECT` | json_object |
12+
| `JSON_SCHEMA` | json_schema |

examples/async_agents_no_streaming.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
async def main():
1111
api_key = os.environ["MISTRAL_API_KEY"]
12+
agent_id = os.environ["MISTRAL_AGENT_ID"]
1213

1314
client = Mistral(api_key=api_key)
1415

1516
chat_response = await client.agents.complete_async(
16-
agent_id="<your_agent_id>",
17+
agent_id=agent_id,
1718
messages=[UserMessage(content="What is the best French cheese?")],
1819
)
1920

examples/async_chat_with_image_no_streaming.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import asyncio
44
import os
55

6-
import httpx
76

87
from mistralai import Mistral
9-
from mistralai.models import ImageURLChunk, TextChunk, UserMessage
8+
from mistralai.models import UserMessage
109

1110

1211
async def main():

examples/async_structured_outputs.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
3+
import asyncio
4+
import os
5+
from pydantic import BaseModel
6+
7+
from mistralai import Mistral
8+
9+
async def main():
10+
11+
api_key = os.environ["MISTRAL_API_KEY"]
12+
client = Mistral(api_key=api_key)
13+
14+
class Explanation(BaseModel):
15+
explanation: str
16+
output: str
17+
18+
class MathDemonstration(BaseModel):
19+
steps: list[Explanation]
20+
final_answer: str
21+
22+
chat_response = await client.chat.parse_async(
23+
model="mistral-large-2411",
24+
messages=[
25+
{"role": "system", "content": "You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning."},
26+
{"role": "user", "content": "How can I solve 8x + 7 = -23"},
27+
],
28+
response_format = MathDemonstration
29+
)
30+
print(chat_response.choices[0].message.parsed)
31+
32+
if __name__ == "__main__":
33+
asyncio.run(main())

examples/chat_with_streaming.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def main():
1010
api_key = os.environ["MISTRAL_API_KEY"]
11-
model = "mistral-tiny"
11+
model = "mistral-large-latest"
1212

1313
client = Mistral(api_key=api_key)
1414

@@ -17,7 +17,7 @@ def main():
1717
messages=[UserMessage(content="What is the best French cheese?")],
1818
):
1919

20-
print(chunk.data.choices[0].delta.content)
20+
print(chunk.data.choices[0].delta.content, end="")
2121

2222

2323
if __name__ == "__main__":

0 commit comments

Comments
 (0)