Repository navigation
Conversation
mistralai 2.0.0 removed the top-level exports (`Mistral`, `UserMessage`, ...) that the adapter imported lazily, so every entry point (`from_mistral`, `format_input`, `generate`, `stream`) crashed with ImportError on the mistralai releases a fresh `outlines[mistral]` install resolves to. Import the client from `mistralai.client` and the message classes from `mistralai.client.models`, keeping the top-level imports as a fallback for mistralai 1.x. The mistral test files imported from the removed surface as well and failed at collection time, so update them too.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
from_mistraland everyMistralTypeAdapter.format_inputpath importedMistral,UserMessage,AssistantMessageandSystemMessagefrom themistralaitop level. mistralai 2.0.0 removed those top-level exports: the package became a namespace package whose client lives atmistralai.clientand whose message classes live atmistralai.client.models. Since themistralextra is declared without a version bound (pyproject.toml:48), a freshpip install "outlines[mistral]"resolves mistralai 3.2.0, and every entry point (from_mistral,format_input,generate,stream) fails with anImportErrorbefore any request is sent.Why
src/outlines/models/mistral.py:81,:101,:120and:545import from themistralaitop level, which mistralai >= 2.0.0 no longer exports (checked against the 2.0.0, 2.10.1, 3.0.0 and 3.2.0 wheels: there is nomistralai/__init__.py; the client is atmistralai.client, the message classes atmistralai.client.modelsandSDKErroratmistralai.client.errors).client.chat.complete/chat.stream/chat.complete_async/chat.stream_async) is unchanged in 3.2.0, so only the import paths need to move.src/outlines/exceptions.py:298, which already resolvesmistralai.client.errorswith anImportErrorfallback for older SDKs, so mistralai 1.x keeps working.Fixes #2070
Changes
src/outlines/models/mistral.py: import the client frommistralai.clientand the message classes frommistralai.client.models, keeping the top-level imports as a fallback for mistralai 1.x (theuv.locktest environment still pins 1.9.11).tests/models/test_mistral.py,tests/models/test_mistral_type_adapter.py,tests/models/test_provider_exceptions.py: these imported from the removed surface themselves and failed at collection time on mistralai >= 2.0.0; updated with the same fallback.tests/models/test_mistral_sdk_compat.py(new): regression tests covering the four entry points (format_inputwithstr/list/Chat, andfrom_mistral) against whichever mistralai release is installed.Testing
On the unpatched tree with mistralai 3.2.0 (what a fresh
outlines[mistral]install resolves), the new tests fail with the reported error:On the patched tree:
The module suite passes both on mistralai 1.9.11 (the version pinned in
uv.lock, used by CI) and on 3.2.0.Checklist
maincommit;pre-commitis installed and configured on your machine, and you ran it before opening the PR;