ocr: lazily import rust bridge inside ocr() to break the import cycle the CodeQL autofix mangled

This commit is contained in:
Ishaan Jaffer 2026-06-22 18:49:03 -07:00
parent 54577a691e
commit 3188f93be0
No known key found for this signature in database

View file

@ -39,8 +39,6 @@ async def aocr(
extra_headers: Optional[Dict[str, Any]] = None,
**kwargs,
) -> OCRResponse:
from litellm.ocr.rust_bridge import rust_ocr, rust_ocr_enabled
"""
Async OCR function.
@ -264,6 +262,10 @@ def ocr(
api_base = dynamic_api_base
# Optional Rust path: hand the whole Mistral OCR call to the Rust bridge.
# Imported lazily to avoid a module-level import cycle (CodeQL flags the
# litellm.ocr.main -> litellm.ocr.rust_bridge edge during package init).
from litellm.ocr.rust_bridge import rust_ocr, rust_ocr_enabled
if custom_llm_provider == "mistral" and rust_ocr_enabled():
return rust_ocr(model, document, api_key, api_base, kwargs)