mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
ocr: add minimal Rust bridge (use_litellm_rust + rust_ocr)
This commit is contained in:
parent
8feefec4f4
commit
c697154bf3
1 changed files with 39 additions and 0 deletions
39
litellm/ocr/rust_bridge.py
Normal file
39
litellm/ocr/rust_bridge.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""
|
||||
Optional Rust-backed OCR path.
|
||||
|
||||
Enable with ``litellm.use_litellm_rust()``; the sync ``litellm.ocr()`` entrypoint
|
||||
then routes supported Mistral calls through the compiled ``litellm_python_bridge``
|
||||
extension, which performs the whole OCR call (URL, headers, HTTP, parse) in Rust.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from litellm.llms.base_llm.ocr.transformation import OCRResponse
|
||||
|
||||
_RUST_OCR_ENABLED = False
|
||||
|
||||
|
||||
def use_litellm_rust(enabled: bool = True) -> None:
|
||||
"""Route supported OCR calls through the Rust ``litellm_python_bridge`` extension."""
|
||||
global _RUST_OCR_ENABLED
|
||||
_RUST_OCR_ENABLED = enabled
|
||||
|
||||
|
||||
def rust_ocr_enabled() -> bool:
|
||||
"""Whether the Rust OCR path has been turned on via ``use_litellm_rust()``."""
|
||||
return _RUST_OCR_ENABLED
|
||||
|
||||
|
||||
def rust_ocr(
|
||||
model: str,
|
||||
document: Dict[str, Any],
|
||||
api_key: Optional[str],
|
||||
api_base: Optional[str],
|
||||
optional_params: Dict[str, Any],
|
||||
) -> OCRResponse:
|
||||
"""Run a Mistral OCR call end-to-end in Rust and wrap the result as ``OCRResponse``."""
|
||||
import litellm_python_bridge
|
||||
|
||||
return OCRResponse(
|
||||
**litellm_python_bridge.ocr(model, document, api_key, api_base, optional_params)
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue