mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-22 00:31:44 +00:00
Extracted from #41733 without the router loop, the cache machine layer, streaming, or the error, timeout and route-pruning work that moved to #41745 litellm-callbacks holds the contract a native call and its host share: Machine, HostOp, CallEvent, the in-process run loop, and Passthrough, which is built only by comparing the caller's inputs with the body the route sends, so a route can never mark a key it rewrote. litellm-host-python (formerly python-interop) owns the CPython driver and the Execution handle, and litellm-callbacks-legacy is the @client wrapper as the native call sees it: function_setup, the deployment hooks, pre_call and post_call, the success and failure fan-out and the deferred proxy release. OCR is the one route on it, and the old core and bridge lifecycles are gone The passthrough rule is the structural fix for the bug #41719 patched in core and #41716 reworks: an inlined remote document no longer counts as the caller's value, so the legacy adapter never hands the caller's URL back into the body. core/tests/ocr/passthrough.rs pins it for every route and document source, including that unchanged values stay passthrough, and callbacks-legacy/tests/payload.rs pins the adapter side with a real pre_call callback Python OCR integration tests that only exercised core behavior now live as Rust tests, so tests/test_litellm_rust keeps the cases that need the full Python stack
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from collections.abc import Sequence
|
|
from typing import Final
|
|
|
|
from litellm.rust_bridge.lifecycle import Await, Complete, drive
|
|
|
|
|
|
class ScriptedExecution:
|
|
"""Plays scripted steps and records how it was resumed and whether it was closed."""
|
|
|
|
def __init__(self, steps: Sequence[Await | Complete]) -> None:
|
|
self._steps: Final = list(steps)
|
|
self.resumed: list[tuple[str, object]] = []
|
|
self.closed = False
|
|
|
|
def start(self) -> Await | Complete:
|
|
return self._steps.pop(0)
|
|
|
|
def resume_value(self, value: object) -> Await | Complete:
|
|
self.resumed.append(("value", value))
|
|
return self._steps.pop(0)
|
|
|
|
def resume_error(self, error: BaseException) -> Await | Complete:
|
|
self.resumed.append(("error", type(error)))
|
|
return self._steps.pop(0)
|
|
|
|
def close(self) -> None:
|
|
self.closed = True
|
|
|
|
|
|
async def ready(value: object) -> object:
|
|
return value
|
|
|
|
|
|
async def failing() -> object:
|
|
raise ValueError("boom")
|
|
|
|
|
|
def test_drive_resumes_each_await_with_its_result_or_error_and_returns_the_completed_value() -> None:
|
|
execution: Final = ScriptedExecution([Await(ready(1)), Await(failing()), Complete("done")])
|
|
|
|
assert asyncio.run(drive(execution)) == "done"
|
|
|
|
assert execution.resumed == [("value", 1), ("error", ValueError)]
|
|
assert execution.closed
|