mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-01 01:18:34 +00:00
* test(rust-bridge): pin Messages and Responses callback contracts on the native path Each test runs the native route and asserts what the Python path does today, so a known gap is a strict xfail that names its reason and the exception it fails with Messages and Responses share one Surface and hook recorder in support/callbacks.py, and each surface folder lists its own expected counts and gaps. Body-level hooks from the function body (pre-request hook, websearch short-circuit, Messages interceptors, planned and legacy agentic loops, streaming deployment hook) are xfail until native runs them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(rust-bridge): give every route folder the same one-concern-per-file layout Route data, the route Surface and the server fixture move into each route folder, and support/ keeps only route-neutral helpers. test_inference.py splits into chat_completions/ and responses/, ocr/test_requests.py splits into requests, failures and settings, and Messages and Responses get streaming and body hook files. Messages request tests that duplicate inference-messages request.rs are removed, and drop_params read from litellm.drop_params is now covered Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(rust-bridge): expect the required-route decline error for unsupported Responses requests Co-Authored-By: Yujong Lee <yujong@berri.ai> * test(rust-bridge): import route data from the route folders in the secrets unit tests Co-Authored-By: Yujong Lee <yujong@berri.ai> * test(rust-bridge): import NoReturn in the OCR dispatch tests Co-Authored-By: Yujong Lee <yujong@berri.ai> * test(rust-bridge): move route-neutral helpers out of support/callbacks.py Co-Authored-By: Yujong Lee <yujong@berri.ai> * test(rust-bridge): cover deployment rejection and concurrent callbacks * test(rust-bridge): assert native serving via the x-litellm-rust marker in the route folder tests Co-Authored-By: Yujong Lee <yujong@berri.ai> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
from typing import Final
|
|
|
|
import pytest
|
|
from pydantic import TypeAdapter
|
|
|
|
import litellm
|
|
from litellm.integrations.custom_logger import CustomLogger
|
|
from litellm.types.utils import CallTypes, ModelResponse
|
|
from tests.test_litellm_rust.chat_completions.data import call
|
|
from tests.test_litellm_rust.messages.data import MESSAGES_TEXT
|
|
from tests.test_litellm_rust.support.callback_recorder import RecordingLogger, request_body
|
|
from tests.test_litellm_rust.support.recording_server import RecordingServer
|
|
from tests.test_litellm_rust.support.routing import assert_served_natively
|
|
|
|
pytestmark = pytest.mark.requires_rust_extension
|
|
|
|
_OBJECT: Final = TypeAdapter(dict[str, object])
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.parametrize("asynchronous", (False, True))
|
|
async def test_returns_a_model_response_and_logs_success_once(server: RecordingServer, asynchronous: bool) -> None:
|
|
recorder: Final = RecordingLogger()
|
|
|
|
result: Final = await call(server, asynchronous=asynchronous, callbacks=[recorder], temperature=0.25)
|
|
|
|
assert_served_natively(server)
|
|
sent: Final = server.requests[0]
|
|
body: Final = _OBJECT.validate_python(sent.body)
|
|
assert sent.path == "/v1/messages"
|
|
assert body["temperature"] == 0.25
|
|
assert request_body(_OBJECT.validate_python(recorder.wait_for("log_pre_api_call")[0].kwargs)) == body
|
|
assert isinstance(result, ModelResponse)
|
|
assert result.choices[0].message.content == MESSAGES_TEXT
|
|
success: Final = await recorder.wait_for_async("async_log_success_event" if asynchronous else "log_success_event")
|
|
assert len(success) == 1
|
|
assert success[0].response is result
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pre_api_call_edits_reach_the_provider(server: RecordingServer) -> None:
|
|
class Edit(CustomLogger):
|
|
def log_pre_api_call(self, model: object, messages: object, kwargs: dict[str, object]) -> None:
|
|
request_body(kwargs)["temperature"] = 0.75
|
|
|
|
await call(server, callbacks=[Edit()])
|
|
|
|
assert _OBJECT.validate_python(server.requests[0].body)["temperature"] == 0.75
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pre_call_deployment_hook_can_delete_keywords(server: RecordingServer) -> None:
|
|
class DropKeywords(CustomLogger):
|
|
async def async_pre_call_deployment_hook(
|
|
self, kwargs: dict[str, object], call_type: CallTypes | None
|
|
) -> dict[str, object]:
|
|
return {name: value for name, value in kwargs.items() if name not in ("temperature", "extra_headers")}
|
|
|
|
litellm.callbacks.append(DropKeywords())
|
|
await call(server, temperature=0.25, extra_headers={"x-deleted": "remove this header"})
|
|
|
|
assert_served_natively(server)
|
|
sent: Final = server.requests[0]
|
|
assert "temperature" not in _OBJECT.validate_python(sent.body)
|
|
assert sent.headers.get("x-deleted") is None
|