Co-authored-by: Antoine <33425718+anth2o@users.noreply.github.com>
Co-authored-by: Bastien <bastien.baret@gmail.com>
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai>
Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Nelson PROIA <144663685+Nelson-PROIA@users.noreply.github.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Quentin <quentin.torroba@mistral.ai>
Co-authored-by: Robin Gullo <robin.gullo@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Clément Drouin 2026-04-28 17:44:07 +02:00 committed by GitHub
parent a83c81ecf5
commit 632ea8c032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
253 changed files with 13965 additions and 2525 deletions

View file

@ -375,9 +375,26 @@ class AnthropicAdapter(APIAdapter):
if last_block.get("type") in {"text", "image", "tool_result"}:
last_block["cache_control"] = {"type": "ephemeral"}
@staticmethod
def _is_adaptive_model(model_name: str) -> bool:
return "opus-4-6" in model_name
# Anthropic models that require the `thinking={"type":"adaptive"}` +
# `output_config.effort` shape and reject the older
# `thinking={"type":"enabled","budget_tokens":...}` shape. Add new
# adaptive-only model families here as Anthropic ships them.
ADAPTIVE_MODEL_TAGS: ClassVar[frozenset[str]] = frozenset({"opus-4-6", "opus-4-7"})
# Anthropic models that have deprecated the `temperature` parameter and
# reject any payload containing it. Add new families here as Anthropic
# ships them.
TEMPERATURE_DEPRECATED_MODEL_TAGS: ClassVar[frozenset[str]] = frozenset({
"opus-4-7"
})
@classmethod
def _is_adaptive_model(cls, model_name: str) -> bool:
return any(tag in model_name for tag in cls.ADAPTIVE_MODEL_TAGS)
@classmethod
def _is_temperature_deprecated_model(cls, model_name: str) -> bool:
return any(tag in model_name for tag in cls.TEMPERATURE_DEPRECATED_MODEL_TAGS)
def _apply_thinking_config(
self,
@ -391,9 +408,11 @@ class AnthropicAdapter(APIAdapter):
) -> None:
has_thinking = self._has_thinking_content(messages)
thinking_level = thinking
temperature_deprecated = self._is_temperature_deprecated_model(model_name)
if thinking_level == "off" and not has_thinking:
payload["temperature"] = temperature
if not temperature_deprecated:
payload["temperature"] = temperature
if max_tokens is not None:
payload["max_tokens"] = max_tokens
else:
@ -405,7 +424,7 @@ class AnthropicAdapter(APIAdapter):
effective_level = thinking_level if thinking_level != "off" else "medium"
if self._is_adaptive_model(model_name):
payload["thinking"] = {"type": "adaptive"}
payload["thinking"] = {"type": "adaptive", "display": "summarized"}
payload["output_config"] = {"effort": effective_level}
default_max = self.DEFAULT_ADAPTIVE_MAX_TOKENS
else:
@ -413,7 +432,8 @@ class AnthropicAdapter(APIAdapter):
payload["thinking"] = {"type": "enabled", "budget_tokens": budget}
default_max = budget + self.DEFAULT_MAX_TOKENS
payload["temperature"] = 1
if not temperature_deprecated:
payload["temperature"] = 1
payload["max_tokens"] = max_tokens if max_tokens is not None else default_max
def _build_payload(