mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-29 01:03:17 +00:00
2.1 KiB
2.1 KiB
- Target invariants; implementation and runtime validation may lag these rules
- Keep this crate a small, domain-neutral foundation: Python/Serde conversion and interpreter-boundary utilities
- No LiteLLM domain dependencies, route types, callback policy, public API registration or cdylib build features
- Generic code alone does not justify extraction: runtime integration stays in
python-bridge/src/execution.rs, host adaptation in itslifecycle.rs
- Use standard PyO3 ownership and conversion APIs
- Prefer
Bound<'py, T>for attached operations/results,Py<T>for retention; binding/unbinding does not copy payloads - Use
pythonizefor selected Serde data, never a JSON-text round trip; share conversion withPythonized<T> - Preserve
PythonizeError's standard conversion intoPyErr; do not stringify original Python exceptions into newValueErrors - Keep serializer-panic containment in
Pythonized<T>: async output conversion can run in an unjoined blocking task and otherwise strand delivery
- Prefer
- Use
Python::detachfor Rust-only work; Python operations require attachment- Keep diagnostic counters in the consumer; wrapper invocations do not measure every interpreter release
- Release exclusive class borrows/locks before Python calls or decrements that can invoke finalizers; expose retained Python edges to GC without calling Python during traversal
- Keep coroutine driving in the shared Python driver and native adapter
- Driver:
litellm/rust_bridge/lifecycle.py; handle:python-bridge/src/lifecycle.rs; native-backed behavior tests:python-bridge/tests/lifecycle.py
- Driver:
- References: ownership, conversions, pythonize errors