From ce59e1821ec599db8d540cf4789b1392bc9bb48c Mon Sep 17 00:00:00 2001 From: Nelson PROIA Date: Fri, 17 Jul 2026 13:05:27 +0200 Subject: [PATCH 1/2] examples: fix broken examples and unblock their type checks - chat_with_image: dead image URL returned 400; use a live image - structured_outputs: mistral-large-2411 rejected as invalid model; use mistral-large-latest - run_example_scripts.yaml: install the [telemetry] extra so observability examples run - redaction.py: import SpanExporter as the base class so mypy accepts it (valid-type) - pre-commit: add pydantic to the pyright hook deps - guard optional message access in the two examples --- .github/workflows/run_example_scripts.yaml | 4 ++-- .pre-commit-config.yaml | 1 + .../mistral/chat/async_chat_with_image_no_streaming.py | 7 +++++-- examples/mistral/chat/async_structured_outputs.py | 7 +++++-- src/mistralai/extra/observability/redaction.py | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run_example_scripts.yaml b/.github/workflows/run_example_scripts.yaml index a14e83e47..ed182f0e1 100644 --- a/.github/workflows/run_example_scripts.yaml +++ b/.github/workflows/run_example_scripts.yaml @@ -34,7 +34,7 @@ jobs: - name: Install client with extras run: | - PACKAGE="dist/$(ls dist | grep whl | head -n 1)[agents]" + PACKAGE="dist/$(ls dist | grep whl | head -n 1)[agents,telemetry]" uv pip install --system "$PACKAGE" examples: @@ -73,7 +73,7 @@ jobs: - name: Install client with extras and run all examples. run: | - PACKAGE="dist/$(ls dist | grep whl | head -n 1)[agents]" + PACKAGE="dist/$(ls dist | grep whl | head -n 1)[agents,telemetry]" uv pip install --system "$PACKAGE" ./scripts/run_examples.sh env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7517b816e..48061d24d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,6 +10,7 @@ repos: rev: v1.1.401 hooks: - id: pyright + additional_dependencies: [pydantic] files: ^(examples/|src/mistralai/|packages/(azure|gcp)/src/mistralai/).*\.py$ exclude: ^src/mistralai/(__init__|sdkhooks|types)\.py$ - repo: https://github.com/pre-commit/mirrors-mypy diff --git a/examples/mistral/chat/async_chat_with_image_no_streaming.py b/examples/mistral/chat/async_chat_with_image_no_streaming.py index 5d2cbdaa4..6f67d71f3 100755 --- a/examples/mistral/chat/async_chat_with_image_no_streaming.py +++ b/examples/mistral/chat/async_chat_with_image_no_streaming.py @@ -21,14 +21,17 @@ async def main(): {"type": "text", "text": "What's in this image?"}, { "type": "image_url", - "image_url": "https://cms.mistral.ai/assets/a64b3821-3a4c-4d4d-b718-d653f3eb7a5e.png?", + "image_url": "https://mistral.ai/_astro/ai-app_Z2q9iqE.webp?dpl=6a57bb9ad483ec680851599b", }, ] ) ], ) - print(chat_response.choices[0].message.content) + if chat_response.choices: + message = chat_response.choices[0].message + if message is not None: + print(message.content) if __name__ == "__main__": diff --git a/examples/mistral/chat/async_structured_outputs.py b/examples/mistral/chat/async_structured_outputs.py index 09ed5737c..3adfaf6f3 100644 --- a/examples/mistral/chat/async_structured_outputs.py +++ b/examples/mistral/chat/async_structured_outputs.py @@ -20,7 +20,7 @@ class MathDemonstration(BaseModel): final_answer: str chat_response = await client.chat.parse_async( - model="mistral-large-2411", + model="mistral-large-latest", messages=[ { "role": "system", @@ -30,7 +30,10 @@ class MathDemonstration(BaseModel): ], response_format=MathDemonstration, ) - print(chat_response.choices[0].message.parsed) + if chat_response.choices: + message = chat_response.choices[0].message + if message is not None: + print(message.parsed) if __name__ == "__main__": diff --git a/src/mistralai/extra/observability/redaction.py b/src/mistralai/extra/observability/redaction.py index fe9319e64..dbd8e74a7 100644 --- a/src/mistralai/extra/observability/redaction.py +++ b/src/mistralai/extra/observability/redaction.py @@ -29,7 +29,8 @@ # Inherit from the real base only for static analysis: linters verify our # export/shutdown/force_flush signatures. At runtime the base is object so # the optional OpenTelemetry SDK is not required to import this module. - _SpanExporterBase = SpanExporter + # Imported (not assigned to a variable) so type checkers accept it as a base. + from opentelemetry.sdk.trace.export import SpanExporter as _SpanExporterBase else: _SpanExporterBase = object From 2305d6213f12f923cbdc3b7955d07a0b537e3b44 Mon Sep 17 00:00:00 2001 From: Nelson PROIA Date: Mon, 20 Jul 2026 15:24:37 +0200 Subject: [PATCH 2/2] examples: use a stable pinned image URL Replace the mistral.ai _astro build asset (per-deploy content hash, would 404 on redeploy) with the Mistral logo pinned to a commit SHA so it can never rot. Addresses review feedback. --- examples/mistral/chat/async_chat_with_image_no_streaming.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mistral/chat/async_chat_with_image_no_streaming.py b/examples/mistral/chat/async_chat_with_image_no_streaming.py index 6f67d71f3..44bdd1b36 100755 --- a/examples/mistral/chat/async_chat_with_image_no_streaming.py +++ b/examples/mistral/chat/async_chat_with_image_no_streaming.py @@ -21,7 +21,7 @@ async def main(): {"type": "text", "text": "What's in this image?"}, { "type": "image_url", - "image_url": "https://mistral.ai/_astro/ai-app_Z2q9iqE.webp?dpl=6a57bb9ad483ec680851599b", + "image_url": "https://raw.githubusercontent.com/mistralai/mistral-common/7edf6f651b3579135f44686e345d51b7e19a536a/docs/assets/logo_favicon.png", }, ] )