Skip to content

Commit

Permalink
chore: 🐝 Update SDK - Generate MISTRALAI MISTRALAI-SDK 1.5.0 (#184)
Browse files Browse the repository at this point in the history
* 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 <bot@speakeasyapi.dev>
Co-authored-by: Alexandre Menasria <alexandre.menasria@mistral.ai>
  • Loading branch information
3 people authored Jan 28, 2025
1 parent 77c7220 commit bcc7748
Show file tree
Hide file tree
Showing 36 changed files with 901 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .genignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pyproject.toml
examples/*
examples/*
src/mistral/extra/*
32 changes: 32 additions & 0 deletions .github/workflows/lint_custom_code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Linting Python custom files

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install ruff
run: pip install ruff

- name: Lint with ruff
# No need to lint the automatically generated Speakeasy code
run: |
ruff check examples/
ruff check src/mistralai/_hooks/ --exclude __init__.py --exclude sdkhooks.py --exclude types.py
ruff check src/mistralai/extra/
48 changes: 48 additions & 0 deletions .github/workflows/test_custom_code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Testing Python custom files

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install Poetry
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
# Install dependencies if cache does not exist
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

- name: Run the 'src/mistralai/extra' package unit tests
run: |
source .venv/bin/activate
python3.12 -m unittest discover -s src/mistralai/extra/tests -t src
18 changes: 12 additions & 6 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
lockVersion: 2.0.0
id: 2d045ec7-2ebb-4f4d-ad25-40953b132161
management:
docChecksum: dbfa566129ede53f4e3b2c91e81f6f74
docChecksum: 553c31591e8dc33a58cb75f348c3aa72
docVersion: 0.0.2
speakeasyVersion: 1.469.11
generationVersion: 2.493.32
releaseVersion: 1.4.0
configChecksum: 46cde4e28fb5efba97051b54ac2e1c83
speakeasyVersion: 1.477.0
generationVersion: 2.497.0
releaseVersion: 1.5.0
configChecksum: 9a5649c5c372dc5fd2fde38a0faee40e
repoURL: https://github.com/mistralai/client-python.git
installationURL: https://github.com/mistralai/client-python.git
published: true
features:
python:
additionalDependencies: 1.0.0
constsAndDefaults: 1.0.5
core: 5.10.4
core: 5.10.5
customCodeRegions: 0.1.1
defaultEnabledRetries: 0.2.0
downloadStreams: 1.0.1
enumUnions: 0.1.0
Expand Down Expand Up @@ -155,6 +156,7 @@ generatedFiles:
- docs/models/jobsapiroutesfinetuningupdatefinetunedmodelrequest.md
- docs/models/jobsout.md
- docs/models/jobsoutobject.md
- docs/models/jsonschema.md
- docs/models/legacyjobmetadataout.md
- docs/models/legacyjobmetadataoutobject.md
- docs/models/listfilesout.md
Expand Down Expand Up @@ -319,6 +321,7 @@ generatedFiles:
- src/mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py
- src/mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py
- src/mistralai/models/jobsout.py
- src/mistralai/models/jsonschema.py
- src/mistralai/models/legacyjobmetadataout.py
- src/mistralai/models/listfilesout.py
- src/mistralai/models/metricout.py
Expand Down Expand Up @@ -566,6 +569,7 @@ examples:
responses:
"422":
application/json: {}
"200": {}
fim_completion_v1_fim_completions_post:
speakeasy-default-fim-completion-v1-fim-completions-post:
requestBody:
Expand All @@ -582,6 +586,7 @@ examples:
responses:
"422":
application/json: {}
"200": {}
agents_completion_v1_agents_completions_post:
speakeasy-default-agents-completion-v1-agents-completions-post:
requestBody:
Expand All @@ -598,6 +603,7 @@ examples:
responses:
"422":
application/json: {}
"200": {}
embeddings_v1_embeddings_post:
speakeasy-default-embeddings-v1-embeddings-post:
requestBody:
Expand Down
4 changes: 2 additions & 2 deletions .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ generation:
oAuth2ClientCredentialsEnabled: true
oAuth2PasswordEnabled: false
python:
version: 1.4.0
version: 1.5.0
additionalDependencies:
dev:
pytest: ^8.2.2
Expand All @@ -23,7 +23,7 @@ python:
clientServerStatusCodesAsErrors: true
defaultErrorName: SDKError
description: Python Client SDK for the Mistral AI API.
enableCustomCodeRegions: false
enableCustomCodeRegions: true
enumFormat: union
envVarPrefix: MISTRAL
fixFlags:
Expand Down
13 changes: 6 additions & 7 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
speakeasyVersion: 1.469.11
speakeasyVersion: 1.477.0
sources:
mistral-azure-source:
sourceNamespace: mistral-azure-source
Expand All @@ -14,11 +14,10 @@ sources:
- latest
mistral-openapi:
sourceNamespace: mistral-openapi
sourceRevisionDigest: sha256:c414dd5eecca5f02fe9012a1d131f696e0257fe100c371609272dbc6c522ef07
sourceBlobDigest: sha256:f48af039106d00de84345fd095fbf4831f18fbeeef07e9ff7bba70a0e07eda07
sourceRevisionDigest: sha256:af4a2854e017abc0ec9e4b557186611dcd69468d82d5ac7f81bfbe49165fc18d
sourceBlobDigest: sha256:9f1bbc418fba3c7b5031bacdf9d431aff476fb4b2aa3838ed50fb3922563703c
tags:
- latest
- speakeasy-sdk-regen-1737393201
targets:
mistralai-azure-sdk:
source: mistral-azure-source
Expand All @@ -37,10 +36,10 @@ targets:
mistralai-sdk:
source: mistral-openapi
sourceNamespace: mistral-openapi
sourceRevisionDigest: sha256:c414dd5eecca5f02fe9012a1d131f696e0257fe100c371609272dbc6c522ef07
sourceBlobDigest: sha256:f48af039106d00de84345fd095fbf4831f18fbeeef07e9ff7bba70a0e07eda07
sourceRevisionDigest: sha256:af4a2854e017abc0ec9e4b557186611dcd69468d82d5ac7f81bfbe49165fc18d
sourceBlobDigest: sha256:9f1bbc418fba3c7b5031bacdf9d431aff476fb4b2aa3838ed50fb3922563703c
codeSamplesNamespace: mistral-openapi-code-samples
codeSamplesRevisionDigest: sha256:3f61d33c46733b24ecd422423900425b381529da038992e59bdb5a9b766bdf89
codeSamplesRevisionDigest: sha256:cbf9b277d16c47816fc5d63b4c69cf0fbd1fe99d424c34ab465d2b61fcc6e5e8
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
* [Server Selection](#server-selection)
* [Custom HTTP Client](#custom-http-client)
* [Authentication](#authentication)
* [Resource Management](#resource-management)
* [Debugging](#debugging)
* [IDE Support](#ide-support)
* [Development](#development)
Expand All @@ -52,6 +53,11 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
<!-- Start SDK Installation [installation] -->
## SDK Installation

> [!NOTE]
> **Python version upgrade policy**
>
> 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.
The SDK can be installed with either *pip* or *poetry* package managers.

### PIP
Expand Down Expand Up @@ -754,6 +760,32 @@ with Mistral(
```
<!-- End Authentication [security] -->

<!-- Start Resource Management [resource-management] -->
## Resource Management

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.

[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers

```python
from mistralai import Mistral
import os
def main():
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
# Rest of application here...


# Or when using async:
async def amain():
async with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
# Rest of application here...
```
<!-- End Resource Management [resource-management] -->

<!-- Start Debugging [debug] -->
## Debugging

Expand Down
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,14 @@ Based on:
### Generated
- [python v1.4.0] .
### Releases
- [PyPI v1.4.0] https://pypi.org/project/mistralai/1.4.0 - .
- [PyPI v1.4.0] https://pypi.org/project/mistralai/1.4.0 - .

## 2025-01-27 13:57:39
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.476.2 (2.495.1) https://github.com/speakeasy-api/speakeasy
### Generated
- [python v1.5.0] .
### Releases
- [PyPI v1.5.0] https://pypi.org/project/mistralai/1.5.0 - .
11 changes: 11 additions & 0 deletions docs/models/jsonschema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# JSONSchema


## Fields

| Field | Type | Required | Description |
| ----------------------- | ----------------------- | ----------------------- | ----------------------- |
| `name` | *str* | :heavy_check_mark: | N/A |
| `schema_definition` | Dict[str, *Any*] | :heavy_check_mark: | N/A |
| `description` | *OptionalNullable[str]* | :heavy_minus_sign: | N/A |
| `strict` | *Optional[bool]* | :heavy_minus_sign: | N/A |
3 changes: 2 additions & 1 deletion docs/models/responseformat.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

| Field | Type | Required | Description |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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. |
| `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. |
| `json_schema` | [OptionalNullable[models.JSONSchema]](../models/jsonschema.md) | :heavy_minus_sign: | N/A |
3 changes: 2 additions & 1 deletion docs/models/responseformats.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ An object specifying the format that the model must output. Setting to `{ "type"
| Name | Value |
| ------------- | ------------- |
| `TEXT` | text |
| `JSON_OBJECT` | json_object |
| `JSON_OBJECT` | json_object |
| `JSON_SCHEMA` | json_schema |
3 changes: 2 additions & 1 deletion examples/async_agents_no_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

async def main():
api_key = os.environ["MISTRAL_API_KEY"]
agent_id = os.environ["MISTRAL_AGENT_ID"]

client = Mistral(api_key=api_key)

chat_response = await client.agents.complete_async(
agent_id="<your_agent_id>",
agent_id=agent_id,
messages=[UserMessage(content="What is the best French cheese?")],
)

Expand Down
3 changes: 1 addition & 2 deletions examples/async_chat_with_image_no_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import asyncio
import os

import httpx

from mistralai import Mistral
from mistralai.models import ImageURLChunk, TextChunk, UserMessage
from mistralai.models import UserMessage


async def main():
Expand Down
33 changes: 33 additions & 0 deletions examples/async_structured_outputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import asyncio
import os
from pydantic import BaseModel

from mistralai import Mistral

async def main():

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

class Explanation(BaseModel):
explanation: str
output: str

class MathDemonstration(BaseModel):
steps: list[Explanation]
final_answer: str

chat_response = await client.chat.parse_async(
model="mistral-large-2411",
messages=[
{"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."},
{"role": "user", "content": "How can I solve 8x + 7 = -23"},
],
response_format = MathDemonstration
)
print(chat_response.choices[0].message.parsed)

if __name__ == "__main__":
asyncio.run(main())
4 changes: 2 additions & 2 deletions examples/chat_with_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

client = Mistral(api_key=api_key)

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

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


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit bcc7748

Please sign in to comment.