chore(deps): migrate to mistralai 2.x - #26
Conversation
The 1.x SDK cannot express the OCR 4 payload: ocr.process has no include_blocks or confidence_scores_granularity, and OCRPageObject carries no blocks/confidence_scores. Both exist in 2.x. This makes them reachable; it does not use them (see #23). The migration is the import root plus the pin. mistralai 2.x is a namespace package, so 'from mistralai import Mistral' becomes 'from mistralai.client import Mistral'. Verified non-issues, contrary to the risks listed in #24: - Retry classification is unchanged. MistralError is shape-identical across 1.12.4 and 2.9.3 (status_code set on the instance in __init__), so _is_retryable gates on the same value and returns the same verdict for 429/500/503 (retry) and 401/400/422 (fail fast) on both. - OCRPageObject is not frozen in 2.x, so the chunked-PDF page.index reassignment still works. - files.upload(file=, purpose=) / files.delete(file_id=) and Mistral(api_key=) are unchanged. Closes #24
|
Warning Review limit reached
Next review available in: 55 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoMigrate to mistralai 2.x (pin + import path update)
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Deprecated mistralai.client import path
|
| from typing import Any | ||
|
|
||
| from mistralai import Mistral | ||
| from mistralai.client import Mistral |
There was a problem hiding this comment.
1. Deprecated mistralai.client import path 🐞 Bug ≡ Correctness
The PR imports Mistral from mistralai.client, a submodule path that was the pre-2.x internal layout; in mistralai 2.x the officially documented and stable import is `from mistralai import Mistral (top-level export), and importing from the internal client` submodule is fragile and may break in a future minor/patch release without notice since it is not part of the public API surface. This contradicts the PR description itself, which states the fix should move to `from mistralai import Mistral`, but the actual diff does the opposite (moves away from the top-level import into the submodule).
Agent Prompt
## Issue description
The diff changes the import statement to `from mistralai.client import Mistral`, but the PR description states the intended fix is the opposite: `from mistralai import Mistral` (top-level import). Importing from the internal `mistralai.client` submodule relies on undocumented internal structure of the 2.x SDK and can break in future point releases.
## Issue Context
The PR's own description block shows the diff as `-from mistralai import Mistral` / `+from mistralai.client import Mistral`, but describes wanting to move to the top-level import. The correct migration for mistralai 2.x is to import `Mistral` from the package root, matching how `Mistral(api_key=...)` is documented in mistralai 2.x usage examples.
## Fix Focus Areas
- mistral_ocr/processor.py[49-49]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Closes #24.
Summary
Bumps
mistralaito 2.x and fixes the one import that moved. Two lines. Thismakes the OCR 4 parameters reachable; it does not use them — that is #23.
Correction to #24: three of the four stated risks are not real
I wrote #24 before probing the 2.x internals. Having done so, the risk section
there is overstated and this PR is far more mechanical than advertised.
Retry classification does not change.
MistralErroris shape-identical in1.12.4 and 2.9.3 — both set
status_codeon the instance in__init__— so_is_retryablereads the same value and returns the same verdict. Ran the exactfunction body against a real
SDKErroron both SDKs:Worth recording separately: two limbs of
_is_retryable(
processor.py:259-268) are dead on both versions. NoRateLimitError/InternalServerError/ServiceUnavailableErrorclass exists in either SDK, sothe name-matching loop never fires; and neither
SDKErrorhas a.responseattribute (it is
.raw_response), so that probe always yieldsNone. Thestatus gate works only via the
getattr(error, "status_code", None)fallback.Pre-existing, not introduced here, and deliberately left alone to keep this
diff at two lines — filed as a follow-up rather than folded in.
OCRPageObjectis not frozen in 2.x, so the chunked-PDFpage.indexreassignment (
processor.py:386) still works.files.upload(file=, purpose=),files.delete(file_id=)andMistral(api_key=)are unchanged.Test plan — observed results
uv run pytest→ 141 passed on 2.9.3. No test file modified.uv run ruff check .→ All checks passed.ruff format --check .→ 18 filesalready formatted.
uv run mypy mistral_ocr/ --ignore-missing-imports→ 18 errors vs 17 on main.The one extra is another line of the same pre-existing complaint at
processor.py:281(untyped**ocr_kwargssplat); 2.x's signature has one moreparameter, so the splat is reported once more. Same root cause, no new defect
class — and it is incidentally proof the new params are present. CI has
continue-on-error: trueon this step.End-to-end parity, real API, same 2-page PDF on both SDKs:
parity.md— byte-identical (cmpclean)metadata.json— identical excluding timestamps, including thefingerprint:
fp:e1ece34158a0d63d4464880bc4bcc517184904c858d19c70dab0735df2caa39bThat satisfies #24's done-when, including the requirement that resume state
survive the upgrade untouched.
Scope / non-goals
No new flags, no blocks/confidence, no
_run_fingerprintchange, no defaultmodel change. #23 remains blocked on nothing but itself after this merges.
Summary by cubic
Migrates
mistralaito 2.x to expose OCR v4 parameters for later use, with no runtime behavior change. Old:mistralai1.x withfrom mistralai import Mistral; new:mistralai>=2.9,<3.0withfrom mistralai.client import Mistral._is_retryablestill gates onMistralError.status_codewith the same decisions.OCRPageObjectmutability and the files API are unchanged; chunked-PDFpage.indexreassignment still works.Written for commit 3e359bf. Summary will update on new commits.