fix(models): Add compatibility shim for mistralai v2.x import path (#…#1927
Closed
shivamnegi1705 wants to merge 1 commit intostrands-agents:mainfrom
Closed
fix(models): Add compatibility shim for mistralai v2.x import path (#…#1927shivamnegi1705 wants to merge 1 commit intostrands-agents:mainfrom
shivamnegi1705 wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Contributor
|
Hi @shivamnegi1705 , thank you for your PR. However, I will close this PR in favor of #1935 We have not tested or gone through Mistral changes, so we cannot reliably say we support Mistral 2.0 We will release a patch change right now to make sure Mistral works as is (forces to v1, through upper bound). We can iterate on 2.0 client of MistralAI in another ticket |
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.
Description
mistralaiv2.0 changed the import path for theMistralclient class frommistralai.Mistraltomistralai.client.Mistral. Sincepyproject.tomlspecifiesmistralai>=1.8.2with no upper bound, fresh installs pull v2.0+ and fail at runtime withAttributeError: module 'mistralai' has no attribute 'Mistral'whenstream()orstructured_output()is called.This PR adds a compatibility shim using
importlib.import_modulethat tries the v2.x path first (mistralai.client.Mistral) and falls back to v1.x (mistralai.Mistral). All threemistralai.Mistral()call sites instream()andstructured_output()are replaced with the resolvedMistralClientalias.Related Issues
Closes #1924
Documentation PR
N/A — no documentation changes needed.
Type of Change
Bug fix
Testing
All 35 unit tests pass (33 existing + 2 new import shim tests).
Reproducing the issue
Import succeeds but runtime usage fails:
After applying the fix
The same script with
mistralai==2.0.4no longer throwsAttributeError. Instead it proceeds to the API call and succeeds.Also verified with
mistralai==1.12.4(v1.x) — works as before with no regressions.New unit tests
test_mistral_client_import_v2: verifies shim resolvesMistralClientfrommistralai.client.Mistral(v2.x path)test_mistral_client_import_v1_fallback: verifies fallback tomistralai.Mistralwhenmistralai.clientis unavailable (v1.x path)I ran
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.