mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
Merge 7104a05ec1 into 85fdea0fd1
This commit is contained in:
commit
14cc571afd
5 changed files with 54 additions and 3 deletions
|
|
@ -21,6 +21,7 @@ from litellm.litellm_core_utils.tool_fields import (
|
|||
tools_without_mcp_servers,
|
||||
)
|
||||
from litellm.llms.anthropic.messages.adapters.transformation import (
|
||||
ANTHROPIC_ONLY_REQUEST_KEYS,
|
||||
AnthropicAdapter,
|
||||
)
|
||||
from litellm.llms.anthropic.messages.context_management import (
|
||||
|
|
@ -56,8 +57,6 @@ if TYPE_CHECKING:
|
|||
from litellm.router import Router
|
||||
from litellm.types.proxy.auth.user_api_key_auth import UserAPIKeyAuth
|
||||
|
||||
# Anthropic-only keys already mapped by the translator; strip on extra_kwargs re-merge.
|
||||
ANTHROPIC_ONLY_REQUEST_KEYS: Final[frozenset[str]] = frozenset({"output_config", "safeguards"})
|
||||
_REQUEST_KWARGS: Final = TypeAdapter(Mapping[str, object])
|
||||
|
||||
_AnthropicMessages: TypeAlias = "list[dict[str, object]]"
|
||||
|
|
|
|||
|
|
@ -215,6 +215,10 @@ from litellm.utils import supports_mid_conversation_system
|
|||
|
||||
from .streaming_iterator import AnthropicSSEStream, AnthropicStreamWrapper
|
||||
|
||||
ANTHROPIC_ONLY_REQUEST_KEYS: Final[frozenset[str]] = frozenset(
|
||||
{"output_config", "safeguards", "inference_geo", "mcp_servers", "speed"}
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObject
|
||||
from litellm.llms.anthropic.messages.safeguards import SafeguardsEvaluator
|
||||
|
|
@ -1272,7 +1276,7 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
"""Copy through anthropic params that do not require translation."""
|
||||
translatable_params: Final = self.translatable_anthropic_params()
|
||||
for k, v in anthropic_message_request.items():
|
||||
if k not in translatable_params: # pass remaining params as is
|
||||
if k not in translatable_params and k not in ANTHROPIC_ONLY_REQUEST_KEYS:
|
||||
new_kwargs[k] = v
|
||||
|
||||
def translate_anthropic_to_openai(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
from dataclasses import replace
|
||||
from typing import Final
|
||||
|
||||
import pytest
|
||||
from integration._support.client import Gateway
|
||||
from integration._support.provider import SharedProvider
|
||||
from integration.translation.case import TranslationTestCase
|
||||
from integration.translation.messages.bases.azure import GPT_5_4_TEST_CASE
|
||||
from integration.translation.runner import assert_translation
|
||||
|
||||
GPT_5_4_ANTHROPIC_ONLY_PARAMS_TEST_CASE: Final = replace(
|
||||
GPT_5_4_TEST_CASE,
|
||||
scenario="anthropic_only_params_dropped",
|
||||
litellm_request={
|
||||
**GPT_5_4_TEST_CASE.litellm_request,
|
||||
"inference_geo": "us",
|
||||
"mcp_servers": [{"type": "url", "url": "https://mcp.example.com/sse", "name": "example"}],
|
||||
"speed": "fast",
|
||||
},
|
||||
)
|
||||
|
||||
CASES: Final = (GPT_5_4_ANTHROPIC_ONLY_PARAMS_TEST_CASE,)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("case", CASES, ids=lambda case: case.id)
|
||||
def test_messages_params_anthropic_only(case: TranslationTestCase, gateway: Gateway, provider: SharedProvider) -> None:
|
||||
assert_translation(case, gateway, provider)
|
||||
|
|
@ -4108,6 +4108,27 @@ def test_translate_anthropic_tool_choice_none():
|
|||
assert result == "none"
|
||||
|
||||
|
||||
def test_translate_anthropic_to_openai_drops_anthropic_only_params() -> None:
|
||||
adapter: Final = LiteLLMAnthropicMessagesAdapter()
|
||||
|
||||
new_kwargs, _ = adapter.translate_anthropic_to_openai(
|
||||
{
|
||||
"model": "gpt-5.4",
|
||||
"max_tokens": 64,
|
||||
"messages": [{"role": "user", "content": "Say hello."}],
|
||||
"inference_geo": "us",
|
||||
"mcp_servers": [{"type": "url", "url": "https://mcp.example.com/sse", "name": "example"}],
|
||||
"speed": "fast",
|
||||
"top_k": 7,
|
||||
}
|
||||
)
|
||||
|
||||
assert "inference_geo" not in new_kwargs
|
||||
assert "mcp_servers" not in new_kwargs
|
||||
assert "speed" not in new_kwargs
|
||||
assert new_kwargs["top_k"] == 7
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# PolyfillResult integration tests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue