mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-17 04:34:25 +00:00
* feat(rust-bridge): scope catalog rules with a contextvar Co-Authored-By: Yujong Lee <yujong@berri.ai> * test(rust-bridge): select native integration routes with scoped rules Co-Authored-By: Yujong Lee <yujong@berri.ai> * test(rust-bridge): run the Rust extension suite without LITELLM_RUST Co-Authored-By: Yujong Lee <yujong@berri.ai> * test(rust-bridge): use scoped catalog rules in dispatch tests Co-Authored-By: Yujong Lee <yujong@berri.ai> * refactor(rust-bridge): keep catalog rules a static global and override them once per test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import asyncio
|
|
import copy
|
|
from collections.abc import Awaitable, Callable, Generator, Mapping
|
|
from contextlib import contextmanager
|
|
from typing import Final
|
|
|
|
from litellm.rust_bridge import catalog
|
|
from litellm.rust_bridge.catalog import Route, RouteRule
|
|
from litellm.rust_bridge.configuration import Rollout
|
|
from tests.test_litellm_rust.support.isolation import rebound
|
|
from tests.test_litellm_rust.support.recording_server import RecordingServer
|
|
from tests.test_litellm_rust.support.served import assert_served_natively
|
|
|
|
__all__ = ["CALL_ID", "assert_served_natively", "call_public", "native_route"]
|
|
|
|
CALL_ID: Final = "callback-contract"
|
|
|
|
|
|
@contextmanager
|
|
def native_route(*routes: Route) -> Generator[None]:
|
|
with rebound(catalog, "RULES", (*(RouteRule(route, Rollout.RUST_REQUIRED) for route in routes), *catalog.RULES)):
|
|
yield
|
|
|
|
|
|
async def call_public(
|
|
create: Callable[..., object],
|
|
acreate: Callable[..., Awaitable[object]],
|
|
request: Mapping[str, object],
|
|
server: RecordingServer,
|
|
*,
|
|
asynchronous: bool,
|
|
**kwargs: object,
|
|
) -> object:
|
|
arguments: Final = {
|
|
**copy.deepcopy(dict(request)),
|
|
"api_key": "test-key",
|
|
"api_base": server.base_url,
|
|
"litellm_call_id": CALL_ID,
|
|
**kwargs,
|
|
}
|
|
if asynchronous:
|
|
return await acreate(**arguments)
|
|
return await asyncio.to_thread(create, **arguments)
|