mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-30 01:52:18 +00:00
* feat(rust): expand gateway configuration parsing * refactor(rust): unify core calls and host lifecycle * fix(config): accept environment references for model rate limits Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(rust): unify core calls and host lifecycle * style(rust): apply rustfmt Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(rust): read environment secrets when litellm is not importable Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(core): drop the duplicate rstest attribute Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(rust): make shared route dispatch route-owned * fix(rust): satisfy Clippy in messages regression test --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
3.1 KiB
3.1 KiB
- Target invariants; implementation and runtime validation may lag these rules
- Keep this crate the CPython runtime adapter and nothing more: Serde marshalling, interpreter detachment, tokio/asyncio glue, the
Executionhandle, the call driver and thePythonBinding,PythonHostCalls,PythonCallHooksandPythonOwnedtraits- No LiteLLM domain dependencies beyond
litellm-host: no route types, noLoggingpolicy, no public API registration, no cdylib build features - The driver emits
SucceededorFailedexactly once and never dispatches after a cancellation; which Python objects consume those events is the lifecycle's business PythonBinding::decode_requestreceives the keyword view the hooks'prepare_argumentsreturned, rewritten in place by the route'sPreflight, not the caller's dict; a binding that decodes from it inherits the lifecycle's rewrites (for the legacy adapter: setup, deployment hooks) and the preflight's (credential inheritance)- A native failure, including one a host op returns as
InvokeError::Native, is classified exactly once through the binding'smap_error; a Python exception raised inside the call, and a failure inprepare_argumentsortransform_response, is raised as is - A failing
map_erroris raised with the native error's text as its__context__, never swallowed
- No LiteLLM domain dependencies beyond
- 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 the native handle
- Driver:
litellm/rust_bridge/lifecycle.py; handle:src/handle.rs; call driver:src/driver.rs; native-backed behavior tests:tests/lifecycle.py - Every lifecycle suspension is awaited inline in the caller's task;
into_futurecreates a separate task and cannot satisfy this contract
- Driver:
- References: ownership, conversions, pythonize errors