mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-01 02:02:20 +00:00
* feat(rust): support the HTTP Responses API Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat(rust): enable native Python inference opt-in Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(rust_bridge): cover only python-only routes in the native load guard Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(rust): keep Python inference rollout disabled * fix(rust): preserve inference defaults and continuation IDs --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
from types import MappingProxyType
|
|
from typing import Final
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
import litellm
|
|
from litellm.rust_bridge.responses.route_host import arguments, connection_defaults, response
|
|
from litellm.rust_bridge.responses.entrypoints import LiteLLMResponsesRequest
|
|
from litellm.types.llms.openai import ResponsesAPIResponse
|
|
|
|
|
|
def test_response_validates_into_the_public_responses_model() -> None:
|
|
built: Final = response(
|
|
MappingProxyType(
|
|
{
|
|
"id": "resp_native",
|
|
"object": "response",
|
|
"created_at": 1,
|
|
"model": "gpt-4o",
|
|
"status": "completed",
|
|
"output": [
|
|
{
|
|
"type": "message",
|
|
"id": "msg_native",
|
|
"role": "assistant",
|
|
"status": "completed",
|
|
"content": [{"type": "output_text", "text": "native", "annotations": []}],
|
|
}
|
|
],
|
|
}
|
|
)
|
|
)
|
|
|
|
assert isinstance(built, ResponsesAPIResponse)
|
|
assert built.id == "resp_native"
|
|
assert built.output[0].content[0].text == "native"
|
|
|
|
|
|
def test_response_rejects_a_payload_missing_required_fields() -> None:
|
|
with pytest.raises(ValidationError):
|
|
response(MappingProxyType({"object": "response"}))
|
|
|
|
|
|
def test_arguments_are_the_public_kwargs_view() -> None:
|
|
kwargs: Final = MappingProxyType({"litellm_metadata": {"user_id": "u"}})
|
|
request: Final = LiteLLMResponsesRequest(
|
|
model="gpt-4o",
|
|
input="hi",
|
|
stream=None,
|
|
api_key=None,
|
|
api_base=None,
|
|
custom_llm_provider="openai",
|
|
extra_headers=None,
|
|
kwargs=kwargs,
|
|
)
|
|
|
|
assert arguments(request) is kwargs
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("global_key", "provider_key", "expected"),
|
|
(
|
|
("global", "provider", "global"),
|
|
(None, "provider", "provider"),
|
|
("", "provider", "provider"),
|
|
(None, None, None),
|
|
),
|
|
)
|
|
def test_connection_defaults_preserve_openai_precedence(
|
|
monkeypatch: pytest.MonkeyPatch, global_key: str | None, provider_key: str | None, expected: str | None
|
|
) -> None:
|
|
monkeypatch.setattr(litellm, "api_key", global_key)
|
|
monkeypatch.setattr(litellm, "openai_key", provider_key)
|
|
monkeypatch.setattr(litellm, "api_base", "https://configured.invalid/v1")
|
|
assert connection_defaults("openai") == (expected, litellm.api_base)
|