Skip to content

Add LiteLLM Rust workspace with Mistral OCR bridge - #31014

Closed
ishaan-berri wants to merge 1 commit into
BerriAI:mainfrom
ishaan-berri:codex/litellm-rust-mistral-ocr
Closed

Add LiteLLM Rust workspace with Mistral OCR bridge#31014
ishaan-berri wants to merge 1 commit into
BerriAI:mainfrom
ishaan-berri:codex/litellm-rust-mistral-ocr

Conversation

@ishaan-berri

@ishaan-berri ishaan-berri commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

  • Add minimal top-level litellm-rust/ workspace with only the crates needed for the first bridge: core, providers, and python-bridge.
  • Shape Rust around LiteLLM route/provider responsibilities:
    • core/src/ocr/ owns OCR shared types and the OcrProviderConfig template trait.
    • providers/src/mistral/ocr/transformation.rs mirrors litellm/llms/mistral/ocr/transformation.py.
    • providers/src/ocr.rs owns Rust-side OCR provider/operation dispatch.
  • Keep the PyO3 bridge intentionally thin: it exports one OCR function, ocr(payload), and delegates OCR routing to Rust.
  • Add litellm/rust_bridge/ as the Python-side bridge package with an explicit OCR provider rollout enum and Python fallback behavior.
  • Keep litellm/ocr/main.py small: after normal provider resolution, it asks litellm.rust_bridge.ocr for a Rust-backed config; disabled, unavailable, or unsupported Rust paths return the existing Python config unchanged.
  • Add Rust CLAUDE.md/README rules for pure transforms, provider tree mapping, bridge shape, parity tests, and future host I/O boundaries.
  • Add a path-scoped Rust GitHub Actions job that runs cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, and cargo test --workspace on Rust changes.
  • Add Python bridge tests for disabled, enabled, unavailable module, and unknown-provider fallback behavior.

Verification

  • uv run black litellm/rust_bridge litellm/ocr/main.py tests/test_litellm/llms/mistral/ocr/test_mistral_ocr_rust_bridge.py
  • uv run ruff check litellm/rust_bridge litellm/ocr/main.py tests/test_litellm/llms/mistral/ocr/test_mistral_ocr_rust_bridge.py
  • uv run pytest tests/test_litellm/llms/mistral/ocr/test_mistral_ocr_transformation.py tests/test_litellm/llms/mistral/ocr/test_mistral_ocr_rust_bridge.py -q
  • cd litellm-rust && cargo fmt --check
  • cd litellm-rust && cargo clippy --workspace --all-targets -- -D warnings
  • cd litellm-rust && cargo test --workspace

Scope

This PR keeps the rollout narrow: Mistral OCR only, route-level Python hook, Python fallback for every disabled/unavailable Rust path. Future OCR providers should add providers/src/<provider>/ocr/transformation.rs and register the provider in the Rust OCR dispatcher plus the Python rollout enum.

@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Too many files changed for review. (132 files found, 100 file limit)

@CLAassistant

CLAassistant commented Jun 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed-hq

codspeed-hq Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing ishaan-berri:codex/litellm-rust-mistral-ocr (ce27d80) with main (dcf1b44)

Open in CodSpeed

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.28571% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/rust_bridge/loader.py 57.14% 15 Missing ⚠️
litellm/rust_bridge/ocr/config.py 76.19% 10 Missing ⚠️
litellm/rust_bridge/ocr/providers.py 90.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread litellm/llms/mistral/ocr/transformation.py Fixed
Comment thread litellm/llms/mistral/ocr/transformation.py Fixed
Comment thread litellm/llms/mistral/ocr/transformation.py Fixed
Comment thread litellm/_rust/bridge.py Fixed
Comment thread litellm/_rust/bridge.py Fixed
@ishaan-berri
ishaan-berri force-pushed the codex/litellm-rust-mistral-ocr branch 2 times, most recently from 18e1b86 to c64c8ab Compare June 22, 2026 22:50
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
Comment thread litellm/ocr/main.py Fixed
@ishaan-berri
ishaan-berri force-pushed the codex/litellm-rust-mistral-ocr branch 4 times, most recently from dead94b to 59e7308 Compare June 22, 2026 23:08
if _RUST_MODULE_LOAD_ATTEMPTED:
return _RUST_MODULE

_RUST_MODULE_LOAD_ATTEMPTED = True
@ishaan-berri
ishaan-berri force-pushed the codex/litellm-rust-mistral-ocr branch from 59e7308 to ce27d80 Compare June 22, 2026 23:26
@ishaan-berri

Copy link
Copy Markdown
Contributor Author

Refiled from an in-repo BerriAI/litellm branch as #31032: #31032

@ishaan-berri

Copy link
Copy Markdown
Contributor Author

Closing this fork-sourced PR in favor of #31032, which comes from BerriAI/litellm.

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.

4 participants