mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-20 10:02:54 +00:00
Merge 0d399196f4 into e04e89c701
This commit is contained in:
commit
17212139ee
2 changed files with 67 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from collections.abc import AsyncIterator, Mapping
|
||||
from collections.abc import AsyncIterator, Mapping, MutableMapping
|
||||
from types import MappingProxyType
|
||||
from typing import TYPE_CHECKING, Any, Final, cast
|
||||
|
||||
|
|
@ -721,6 +721,23 @@ class AmazonAnthropicClaudeMessagesConfig(
|
|||
requested_thinking: Final = anthropic_messages_optional_request_params.get("thinking")
|
||||
requested_display_updates: Final = AnthropicModelInfo().is_thinking_display_updates_used(requested_thinking)
|
||||
drop_params: Final = getattr(litellm_params, "drop_params", None) is True
|
||||
# Opus 5.5 and the other adaptive models that reject thinking.type=enabled
|
||||
# still receive that shape from Claude Code. Translate it before the shared
|
||||
# Messages transform copies it into the Bedrock body. Models that still
|
||||
# accept the legacy shape (the 4.6 family) are left alone.
|
||||
# The messages boundary still types this payload as a bare dict. Name the
|
||||
# mapping the translator mutates so basedpyright does not count an unknown
|
||||
# argument, without putting MutableMapping in an annotation.
|
||||
typed_optional_params: Final = cast( # cast-ok: [LIT006] untyped messages params dict at this boundary
|
||||
MutableMapping[str, object],
|
||||
anthropic_messages_optional_request_params,
|
||||
)
|
||||
AnthropicModelInfo.translate_legacy_thinking_for_adaptive_model(
|
||||
model=model,
|
||||
optional_params=typed_optional_params,
|
||||
custom_llm_provider="bedrock",
|
||||
drop_params=drop_params,
|
||||
)
|
||||
self._clamp_adaptive_reasoning_effort_for_bedrock(
|
||||
model=model,
|
||||
optional_params=anthropic_messages_optional_request_params,
|
||||
|
|
|
|||
|
|
@ -706,6 +706,55 @@ def test_bedrock_invoke_messages_transform_adds_name_when_tool_missing_name():
|
|||
assert result["tools"][0]["name"] == "litellm_unnamed_tool_0"
|
||||
|
||||
|
||||
def test_bedrock_invoke_messages_translates_enabled_thinking_for_opus_5_5(
|
||||
local_model_cost_map,
|
||||
):
|
||||
"""Opus 5.5 rejects thinking.type=enabled. Claude Code still sends it, with no
|
||||
clear_thinking edit, so the translation has to happen on the plain request."""
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
|
||||
cfg = AmazonAnthropicClaudeMessagesConfig()
|
||||
optional_params = {
|
||||
"max_tokens": 32000,
|
||||
"stream": False,
|
||||
"thinking": {"type": "enabled", "budget_tokens": 2048},
|
||||
}
|
||||
result = cfg.transform_anthropic_messages_request(
|
||||
model="eu.anthropic.claude-opus-5-5",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
anthropic_messages_optional_request_params=copy.deepcopy(optional_params),
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={},
|
||||
)
|
||||
assert result["thinking"]["type"] == "adaptive"
|
||||
assert "budget_tokens" not in result["thinking"]
|
||||
assert result["output_config"]["effort"]
|
||||
assert "output_config" in result
|
||||
|
||||
|
||||
def test_bedrock_invoke_messages_keeps_caller_output_config_effort_for_opus_5_5(
|
||||
local_model_cost_map,
|
||||
):
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
|
||||
cfg = AmazonAnthropicClaudeMessagesConfig()
|
||||
optional_params = {
|
||||
"max_tokens": 32000,
|
||||
"stream": False,
|
||||
"thinking": {"type": "enabled", "budget_tokens": 2048},
|
||||
"output_config": {"effort": "low"},
|
||||
}
|
||||
result = cfg.transform_anthropic_messages_request(
|
||||
model="eu.anthropic.claude-opus-5-5",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
anthropic_messages_optional_request_params=copy.deepcopy(optional_params),
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={},
|
||||
)
|
||||
assert result["thinking"]["type"] == "adaptive"
|
||||
assert result["output_config"]["effort"] == "low"
|
||||
|
||||
|
||||
def test_bedrock_invoke_messages_skips_thinking_injection_when_already_enabled(
|
||||
local_model_cost_map,
|
||||
):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue