mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-23 00:41:40 +00:00
* wip * refactor(tests): move sdk function tracing into rust python harness * dead code * fix: handle harness keyboard interrupts * refactor(tests): deduplicate rust python harness helpers * fix(harness): expose validated strategy choices * wip * refactor(harness): let strategies own parity reports * docs(harness): update strategy structure * refactor(harness): localize strategy report views * wip * fix(harness): satisfy mapping runner type checks * fix(harness): clarify trace parity output * wip * fix(harness): clarify unit mapping report * fix(harness): finalize trace parity contracts * refactor(harness): structure parity contracts * feat: derive unit test mapping from traces * feat(harness): map rstest test families * feat(ocr): port Azure document intelligence tests * feat(harness): enforce complete unit mappings * feat(ocr): add reducto core transforms * feat(harness): classify host-only unit tests * fix(ocr): complete Rust provider plumbing * fix(harness): reuse OCR parity workers
35 lines
1 KiB
Python
35 lines
1 KiB
Python
"""Loader for the packaged LiteLLM Rust extension."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from types import ModuleType
|
|
from typing import Final
|
|
|
|
_BRIDGE_SENTINEL: Final = object()
|
|
_cached_bridge: ModuleType | None | object = _BRIDGE_SENTINEL
|
|
|
|
|
|
def get_native_bridge() -> ModuleType | None:
|
|
"""Return the packaged Rust extension, or ``None`` when unavailable."""
|
|
global _cached_bridge
|
|
if _cached_bridge is not _BRIDGE_SENTINEL:
|
|
return _cached_bridge if isinstance(_cached_bridge, ModuleType) else None
|
|
|
|
try:
|
|
from litellm.rust_bridge import _native
|
|
except ImportError:
|
|
_cached_bridge = None
|
|
return None
|
|
_cached_bridge = _native
|
|
return _native
|
|
|
|
|
|
def reset_native_bridge_cache() -> None:
|
|
"""Forget the cached extension so the next lookup reimports it from disk."""
|
|
global _cached_bridge
|
|
_cached_bridge = _BRIDGE_SENTINEL
|
|
|
|
|
|
def native_bridge_available() -> bool:
|
|
"""Whether the packaged Rust extension is importable."""
|
|
return get_native_bridge() is not None
|