Skip to content

fix(mistral): update imports for mistralai v2 SDK - #1020

Merged
njbrake merged 3 commits into
mainfrom
fix/mistral-v2-imports
Apr 13, 2026
Merged

njbrake merged 3 commits into
mainfrom
fix/mistral-v2-imports

Conversation

@njbrake

@njbrake njbrake commented Apr 13, 2026

Copy link
Copy Markdown
Member

Description

The mistralai v2 SDK (released 2026-03-10) moved all types under a mistralai.client namespace and renamed several batch-related types (BatchJobOut -> BatchJob, BatchJobsOut -> ListBatchJobsResponse). Error types moved from mistralai.models to mistralai.client.errors.

This PR bumps the minimum version to >=2.0.0 and updates all import paths accordingly. It also fixes _convert_models_list to handle v2's UnknownModelListData type which lacks id/created/owned_by fields, and updates response format tests to handle v2's dict return from response_format_from_pydantic_model.

PR Type

  • 🐛 Bug Fix

Relevant issues

Fixes #1018

Checklist

  • I understand the code I am submitting.
  • I have added unit tests that prove my fix/feature works
  • I have run this code locally and verified it fixes the issue.
  • New and existing tests pass locally
  • Documentation was updated where necessary
  • I have read and followed the contribution guidelines
  • AI Usage:
    • No AI was used.
    • AI was used for drafting/refactoring.
    • This is fully AI-generated.

AI Usage Information

  • AI Model used: Claude Opus 4.6

  • AI Developer Tool used: Claude Code

  • Any other info you'd like to share: Used to investigate v2 import path changes and update all references

  • I am an AI Agent filling out this form (check box if true)

The mistralai v2 SDK moved all types under a `mistralai.client` namespace
and renamed several batch-related types. This bumps the minimum version
to >=2.0.0 and updates all import paths accordingly.

Fixes #1018

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mistralai v2 pins opentelemetry-semantic-conventions<0.61, which is
incompatible with opentelemetry-sdk 1.40.0 (requires ==0.61b0). Relaxing
the platform extra's floor to >=1.30.0 lets the resolver pick sdk 1.39.x
which pairs with sem-conventions 0.60b1 in mistralai's range.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@njbrake
njbrake temporarily deployed to integration-tests April 13, 2026 10:01 — with GitHub Actions Inactive
@njbrake
njbrake temporarily deployed to integration-tests April 13, 2026 10:01 — with GitHub Actions Inactive
@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/any_llm/providers/mistral/utils.py 85.71% 1 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
src/any_llm/providers/mistral/mistral.py 98.47% <100.00%> (ø)
src/any_llm/providers/mistral/utils.py 70.80% <85.71%> (-0.46%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@njbrake njbrake added the run-integration-tests Put this label on a PR to trigger the integration test suite: works with forks label Apr 13, 2026
@github-actions github-actions Bot removed the run-integration-tests Put this label on a PR to trigger the integration test suite: works with forks label Apr 13, 2026
@njbrake
njbrake merged commit e7b6243 into main Apr 13, 2026
16 of 17 checks passed
@njbrake
njbrake deleted the fix/mistral-v2-imports branch April 13, 2026 10:16
peteski22 added a commit that referenced this pull request Apr 14, 2026
…nversion

The mistralai v2 SDK (introduced in #1020) types `choice.message` as
`AssistantMessage | None`, but `_create_mistral_completion_from_response`
dereferenced `message_data.content` and `message_data.tool_calls` without a
None guard. This produced five `union-attr` errors under mypy strict mode and
left CI in a flaky state (whichever resolver shuffled mistralai's typing first
broke the lint job).

Add an explicit `ValueError` guard so the converter fails loudly rather than
silently emitting a truncated `ChatCompletion`, plus a unit test that covers
the new path.
peteski22 added a commit that referenced this pull request Apr 14, 2026
…nversion

The mistralai v2 SDK (introduced in #1020) types `choice.message` as
`AssistantMessage | None`, but `_create_mistral_completion_from_response`
dereferenced `message_data.content` and `message_data.tool_calls` without a
None guard. This produced five `union-attr` errors under mypy strict mode and
left CI in a flaky state (whichever resolver shuffled mistralai's typing first
broke the lint job).

Add an explicit `ValueError` guard so the converter fails loudly rather than
silently emitting a truncated `ChatCompletion`, plus a unit test that covers
the new path.
peteski22 added a commit that referenced this pull request Apr 14, 2026
## Description

The mistralai v2 SDK (adopted in #1020) types `choice.message` as
`AssistantMessage | None`, but
`_create_mistral_completion_from_response` dereferenced
`message_data.content` and `message_data.tool_calls` without a None
guard. This produced five `union-attr` errors under mypy strict mode:

```
src/any_llm/providers/mistral/utils.py:174: error: Item "None" of "AssistantMessage | None" has no attribute "content"  [union-attr]
src/any_llm/providers/mistral/utils.py:175: error: ... [union-attr]
src/any_llm/providers/mistral/utils.py:181: error: ... [union-attr]
src/any_llm/providers/mistral/utils.py:183: error: ... [union-attr]
src/any_llm/providers/mistral/utils.py:201: error: ... [union-attr]
```

The lint job on `main` has been intermittently failing since #1020
merged — whichever CI run hit the resolver state where mistralai's
tightened typing was visible would fail. The most recent failure is on
PR #1028.

### Fix

Add an explicit `ValueError` guard at the top of the loop so the
converter fails loudly rather than silently emitting a truncated
`ChatCompletion`. A real chat-completion choice always carries a
message; if the SDK ever hands us `None`, we want to know rather than
drop the choice silently.

Includes a unit test that covers the new guard path.

## PR Type

- 🐛 Bug Fix

## Relevant issues

Regression introduced by #1020 (`fix(mistral): update imports for
mistralai v2 SDK`).

## Checklist

- [x] I understand the code I am submitting.
- [x] I have added unit tests that prove my fix/feature works
- [x] I have run this code locally and verified it fixes the issue.
- [x] New and existing tests pass locally
- [x] Documentation was updated where necessary
- [x] I have read and followed the [contribution
guidelines](https://github.com/mozilla-ai/any-llm/blob/main/CONTRIBUTING.md)
- [x] **AI Usage:**
    - [x] AI was used for drafting/refactoring.

## AI Usage Information

- AI Model used: Claude Opus 4.6 (1M context)
- AI Developer Tool used: Claude Code
- Any other info you'd like to share:

- [ ] I am an AI Agent filling out this form (check box if true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Mistral client no longer working

1 participant