@@ -104,7 +104,7 @@ It's also possible to write a standalone Python script without needing to set up
104104``` python
105105# !/usr/bin/env -S uv run --script
106106# /// script
107- # requires-python = ">=3.9 "
107+ # requires-python = ">=3.10 "
108108# dependencies = [
109109# "mistralai",
110110# ]
@@ -374,38 +374,41 @@ You can run the examples in the `examples/` directory using `uv run`.
374374
375375** Prerequisites**
376376
377- Before you begin, ensure you have ` AZUREAI_ENDPOINT ` and an ` AZURE_API_KEY ` . To obtain these, you will need to deploy Mistral on Azure AI.
377+ Before you begin, ensure you have ` AZURE_ENDPOINT ` and an ` AZURE_API_KEY ` . To obtain these, you will need to deploy Mistral on Azure AI.
378378See [ instructions for deploying Mistral on Azure AI here] ( https://docs.mistral.ai/deployment/cloud/azure/ ) .
379379
380+ ** Step 1: Install**
381+
382+ ``` bash
383+ pip install mistralai
384+ ```
385+
386+ ** Step 2: Example Usage**
387+
380388Here's a basic example to get you started. You can also run [ the example in the ` examples ` directory] ( /examples/azure ) .
381389
382390``` python
383- import asyncio
384391import os
392+ from mistralai.azure.client import MistralAzure
385393
386- from mistralai_azure import MistralAzure
387-
394+ # The SDK automatically injects api-version as a query parameter
388395client = MistralAzure(
389- azure_api_key = os.getenv(" AZURE_API_KEY" , " " ),
390- azure_endpoint = os.getenv(" AZURE_ENDPOINT" , " " )
396+ api_key = os.environ[" AZURE_API_KEY" ],
397+ server_url = os.environ[" AZURE_ENDPOINT" ],
398+ api_version = " 2024-05-01-preview" , # Optional, this is the default
391399)
392400
393- async def main () -> None :
394- res = await client.chat.complete_async(
395- max_tokens = 100 ,
396- temperature = 0.5 ,
397- messages = [
398- {
399- " content" : " Hello there!" ,
400- " role" : " user"
401- }
402- ]
403- )
404- print (res)
405-
406- asyncio.run(main())
401+ res = client.chat.complete(
402+ model = os.environ[" AZURE_MODEL" ],
403+ messages = [
404+ {
405+ " role" : " user" ,
406+ " content" : " Hello there!" ,
407+ }
408+ ],
409+ )
410+ print (res.choices[0 ].message.content)
407411```
408- The documentation for the Azure SDK is available [ here] ( packages/mistralai_azure/README.md ) .
409412
410413### Google Cloud
411414
@@ -422,40 +425,43 @@ gcloud auth application-default login
422425
423426** Step 1: Install**
424427
425- Install the extras dependencies specific to Google Cloud:
426-
427428``` bash
429+ pip install mistralai
430+ # For GCP authentication support (required):
428431pip install " mistralai[gcp]"
429432```
430433
431434** Step 2: Example Usage**
432435
433- Here's a basic example to get you started.
434-
435- ``` python
436- import asyncio
437- from mistralai_gcp import MistralGoogleCloud
436+ Here's a basic example to get you started. You can also run [ the example in the ` examples ` directory] ( /examples/gcp ) .
438437
439- client = MistralGoogleCloud()
438+ The SDK automatically:
439+ - Detects credentials via ` google.auth.default() `
440+ - Auto-refreshes tokens when they expire
441+ - Builds the Vertex AI URL from ` project_id ` and ` region `
440442
443+ ``` python
444+ import os
445+ from mistralai.gcp.client import MistralGCP
441446
442- async def main () -> None :
443- res = await client.chat.complete_async(
444- model = " mistral-small-2402" ,
445- messages = [
446- {
447- " content" : " Hello there!" ,
448- " role" : " user"
449- }
450- ]
451- )
452- print (res)
447+ # The SDK auto-detects credentials and builds the Vertex AI URL
448+ client = MistralGCP(
449+ project_id = os.environ.get(" GCP_PROJECT_ID" ), # Optional: auto-detected from credentials
450+ region = " us-central1" , # Default: europe-west4
451+ )
453452
454- asyncio.run(main())
453+ res = client.chat.complete(
454+ model = " mistral-small-2503" ,
455+ messages = [
456+ {
457+ " role" : " user" ,
458+ " content" : " Hello there!" ,
459+ }
460+ ],
461+ )
462+ print (res.choices[0 ].message.content)
455463```
456464
457- The documentation for the GCP SDK is available [ here] ( packages/mistralai_gcp/README.md ) .
458-
459465
460466<!-- Start Available Resources and Operations [operations] -->
461467## Available Resources and Operations
@@ -674,8 +680,8 @@ with Mistral(
674680 api_key = os.getenv(" MISTRAL_API_KEY" , " " ),
675681) as mistral:
676682
677- res = mistral.models.list(,
678- RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ))
683+ res = mistral.models.list(
684+ retries = RetryConfig(" backoff" , BackoffStrategy(1 , 50 , 1.1 , 100 ), False ))
679685
680686 # Handle response
681687 print (res)
0 commit comments