mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-29 01:42:19 +00:00
compact beta takes precedence over context-management beta
When mixed edit types are present (e.g. summarize + compact), only emit the compact beta header. Previously both betas were appended independently per edit.
This commit is contained in:
parent
dcba26c8aa
commit
9e85c8bf14
2 changed files with 33 additions and 8 deletions
|
|
@ -425,14 +425,21 @@ class AnthropicModelInfo(BaseLLMModelInfo):
|
|||
edits = context_management.get("edits", [])
|
||||
elif isinstance(context_management, list):
|
||||
edits = context_management
|
||||
for edit in edits:
|
||||
edit_type = edit.get("type", "")
|
||||
if edit_type in ("compact_20260112", "compaction"):
|
||||
betas.append(ANTHROPIC_BETA_HEADER_VALUES.COMPACT_2026_01_12.value)
|
||||
else:
|
||||
betas.append(
|
||||
ANTHROPIC_BETA_HEADER_VALUES.CONTEXT_MANAGEMENT_2025_06_27.value
|
||||
)
|
||||
has_compact = any(
|
||||
edit.get("type", "") in ("compact_20260112", "compaction")
|
||||
for edit in edits
|
||||
)
|
||||
has_other_edits = any(
|
||||
edit.get("type", "")
|
||||
and edit.get("type", "") not in ("compact_20260112", "compaction")
|
||||
for edit in edits
|
||||
)
|
||||
if has_compact:
|
||||
betas.append(ANTHROPIC_BETA_HEADER_VALUES.COMPACT_2026_01_12.value)
|
||||
elif has_other_edits:
|
||||
betas.append(
|
||||
ANTHROPIC_BETA_HEADER_VALUES.CONTEXT_MANAGEMENT_2025_06_27.value
|
||||
)
|
||||
|
||||
return list(set(betas))
|
||||
|
||||
|
|
|
|||
|
|
@ -1340,3 +1340,21 @@ class TestGetAnthropicBetaListContextManagement:
|
|||
)
|
||||
assert "compact-2026-01-12" not in betas
|
||||
assert "context-management-2025-06-27" not in betas
|
||||
|
||||
def test_mixed_edits_uses_compact_beta(self):
|
||||
from litellm.llms.anthropic.common_utils import AnthropicModelInfo
|
||||
|
||||
info = AnthropicModelInfo()
|
||||
betas = info.get_anthropic_beta_list(
|
||||
model="claude-sonnet-4-6",
|
||||
optional_params={
|
||||
"context_management": {
|
||||
"edits": [
|
||||
{"type": "summarize"},
|
||||
{"type": "compact_20260112"},
|
||||
],
|
||||
}
|
||||
},
|
||||
)
|
||||
assert "compact-2026-01-12" in betas
|
||||
assert "context-management-2025-06-27" not in betas
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue