mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
fix(rust-bridge): keep proxy /v1/messages calls on Rust when a cache or shared session is configured
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
66c8f5b1a9
commit
473e1a442e
7 changed files with 30 additions and 9 deletions
|
|
@ -104,7 +104,6 @@ _FEATURES: Final[detectors.Detectors] = MappingProxyType(
|
|||
{
|
||||
**detectors.COMMON,
|
||||
Feature.SAFEGUARDS_CLASSIFIER: route_detectors.safeguards_classifier,
|
||||
Feature.RESPONSE_CACHE: detectors.response_cache,
|
||||
Feature.MODIFY_PARAMS: detectors.modify_params,
|
||||
Feature.WORKLOAD_IDENTITY: route_detectors.anthropic_workload_identity,
|
||||
Feature.CACHE_CONTROL_INJECTION: detectors.cache_control_injection,
|
||||
|
|
|
|||
|
|
@ -169,7 +169,6 @@ MESSAGES_PYTHON_FEATURES: Final = COMMON_PYTHON_FEATURES | {
|
|||
Feature.PRE_REQUEST_HOOK,
|
||||
Feature.WEBSEARCH_INTERCEPTION,
|
||||
Feature.MESSAGES_INTERCEPTOR,
|
||||
Feature.RESPONSE_CACHE,
|
||||
Feature.MODIFY_PARAMS,
|
||||
Feature.WORKLOAD_IDENTITY,
|
||||
Feature.CACHE_CONTROL_INJECTION,
|
||||
|
|
@ -208,7 +207,7 @@ RULES: Final[Rules] = (
|
|||
RouteRule(Route.OCR, Rollout.RUST_REQUIRED),
|
||||
RouteRule(Route.MESSAGES, Rollout.PYTHON_ONLY, targets=frozenset({Target.CHAT_COMPLETIONS, Target.RESPONSES})),
|
||||
RouteRule(Route.MESSAGES, Rollout.PYTHON_ONLY, features=MESSAGES_PYTHON_FEATURES),
|
||||
RouteRule(Route.MESSAGES, Rollout.RUST_OPT_IN, providers=frozenset({"anthropic"})),
|
||||
RouteRule(Route.MESSAGES, Rollout.RUST_OPT_IN, providers=frozenset({"anthropic", "deepseek", "vertex_ai"})),
|
||||
RouteRule(Route.MESSAGES, Rollout.PYTHON_ONLY),
|
||||
RouteRule(Route.RESPONSES, Rollout.PYTHON_ONLY, features=RESPONSES_PYTHON_FEATURES),
|
||||
RouteRule(Route.RESPONSES, Rollout.PYTHON_ONLY),
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ def mock_response(request: NativeCall) -> bool:
|
|||
|
||||
|
||||
def caller_client(request: NativeCall) -> bool:
|
||||
"""Python sends through the caller's HTTP client or shared session."""
|
||||
return present(request, "client") or present(request, "shared_session")
|
||||
"""Python sends through the caller's HTTP client. The proxy's shared session is only a pool native replaces."""
|
||||
return present(request, "client")
|
||||
|
||||
|
||||
def extra_body(request: NativeCall) -> bool:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from litellm.messages.dispatch import (
|
|||
)
|
||||
from litellm.proxy import proxy_server
|
||||
from litellm.rust_bridge.bindings import NativeBinding
|
||||
from litellm.rust_bridge.catalog import Feature, Route, RouteRule, Rules, Target
|
||||
from litellm.rust_bridge.catalog import MESSAGES_PYTHON_FEATURES, Feature, Route, RouteRule, Rules, Target
|
||||
from litellm.rust_bridge.configuration import Rollout
|
||||
from litellm.rust_bridge.messages.entrypoints import NATIVE_AMESSAGES, NATIVE_MESSAGES, NativeAmessages, NativeMessages
|
||||
from litellm.rust_bridge.public_call import NativeCall
|
||||
|
|
@ -228,6 +228,25 @@ def test_only_requests_that_pass_through_to_a_messages_api_reach_a_messages_targ
|
|||
assert result is (native_result if passes_through else python_result)
|
||||
|
||||
|
||||
def test_proxy_cache_and_shared_session_keep_messages_native(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
model: Final = "anthropic/claude-sonnet-4-5"
|
||||
python_result: Final = response(model)
|
||||
native_result: Final = response(model)
|
||||
monkeypatch.setattr(litellm, "cache", Cache())
|
||||
result: Final = _DISPATCH.run(
|
||||
(16, MESSAGES, model),
|
||||
{"shared_session": object()},
|
||||
python=lambda *call_args, **call_kwargs: python_result,
|
||||
binding=messages_binding(lambda request: native_result),
|
||||
native=lambda hook, request, call_args, call_kwargs: hook(request),
|
||||
rules=(
|
||||
RouteRule(Route.MESSAGES, Rollout.PYTHON_ONLY, features=MESSAGES_PYTHON_FEATURES),
|
||||
RouteRule(Route.MESSAGES, Rollout.RUST_REQUIRED),
|
||||
),
|
||||
)
|
||||
assert result is native_result
|
||||
|
||||
|
||||
DANGEROUS_TOOL_USE: Final = [{"type": "dangerous_tool_use", "classifier_context": {"permission_mode": "auto"}}]
|
||||
CLASSIFIER_SETTINGS: Final = {"safeguards_classifier_model": "gpt-oss-120b"}
|
||||
|
||||
|
|
@ -457,7 +476,6 @@ ADVISOR_TOOL: Final = {"type": ANTHROPIC_ADVISOR_TOOL_TYPE, "name": "advisor", "
|
|||
(Feature.CALLER_CLIENT, "anthropic/claude-sonnet-4-5", {"client": object()}, {}),
|
||||
(Feature.TIMEOUT_VARIANTS, "anthropic/claude-sonnet-4-5", {"request_timeout": 5}, {}),
|
||||
(Feature.AGENTIC_LOOP_HOOK, "anthropic/claude-sonnet-4-5", {}, {"callbacks": [_Agentic()]}),
|
||||
(Feature.RESPONSE_CACHE, "anthropic/claude-sonnet-4-5", {}, {"cache": Cache()}),
|
||||
(Feature.TLS_POLICY, "anthropic/claude-sonnet-4-5", {}, {"ssl_security_level": "DEFAULT@SECLEVEL=1"}),
|
||||
(Feature.MODIFY_PARAMS, "anthropic/claude-sonnet-4-5", {}, {"modify_params": True}),
|
||||
(
|
||||
|
|
|
|||
|
|
@ -260,7 +260,6 @@ ENCODED_ID: Final = ResponsesAPIRequestUtils._build_encrypted_item_id("deploymen
|
|||
(Feature.MOCK_RESPONSE, {"mock_response": "hi"}, {}),
|
||||
(Feature.PROXY_MCP_TOOLS, {"tools": [{"type": "mcp", "server_label": "g", "server_url": "litellm_proxy"}]}, {}),
|
||||
(Feature.CALLER_CLIENT, {"client": object()}, {}),
|
||||
pytest.param(Feature.CALLER_CLIENT, {"shared_session": object()}, {}, id="shared-session"),
|
||||
pytest.param(Feature.EXTRA_BODY, {"extra_body": {"stream": True}}, {}, id="extra-body-stream"),
|
||||
pytest.param(
|
||||
Feature.PROVIDER_AFFINITY,
|
||||
|
|
|
|||
|
|
@ -128,3 +128,9 @@ def test_empty_constraints_match_nothing() -> None:
|
|||
assert catalog.decision(
|
||||
RouteContext(Route.OCR, features=frozenset({Feature.SAFEGUARDS_CLASSIFIER})), rules
|
||||
) is Decision.PYTHON
|
||||
|
||||
|
||||
@pytest.mark.parametrize("provider", ("anthropic", "deepseek", "vertex_ai"))
|
||||
def test_messages_passthrough_providers_opt_in_to_rust(provider: str) -> None:
|
||||
context: Final = RouteContext(Route.MESSAGES, provider=provider, model="claude-sonnet-4-6", target=Target.MESSAGES)
|
||||
assert catalog.rollout(context) is Rollout.RUST_OPT_IN
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ def _wrap_nested_level(value: object, depth: int) -> object:
|
|||
(detectors.prompt_management, {"model": "litellm_agent/gpt-5"}, True),
|
||||
(detectors.prompt_management, {"model": "gpt-5"}, False),
|
||||
(detectors.caller_client, {"client": object()}, True),
|
||||
(detectors.caller_client, {"shared_session": object()}, True),
|
||||
(detectors.caller_client, {"shared_session": object()}, False),
|
||||
(detectors.caller_client, {"client": None, "shared_session": None}, False),
|
||||
(detectors.caller_client, {}, False),
|
||||
(detectors.extra_body, {"extra_body": {"stream": True}}, True),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue