v2.13.0 (#733)
Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai> Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com> Co-authored-by: Peter Evers <peter.evers@mistral.ai> Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai> Co-authored-by: Quentin <quentin.torroba@mistral.ai> Co-authored-by: Val <102326092+vdeva@users.noreply.github.com> Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
198277af3f
commit
ad0d5c9520
61 changed files with 969 additions and 461 deletions
|
|
@ -324,12 +324,6 @@ class AnthropicAdapter(APIAdapter):
|
|||
"prompt-caching-2024-07-31,"
|
||||
"context-1m-2025-08-07"
|
||||
)
|
||||
THINKING_BUDGETS: ClassVar[dict[str, int]] = {
|
||||
"low": 1024,
|
||||
"medium": 10_000,
|
||||
"high": 32_000,
|
||||
"max": 128_000,
|
||||
}
|
||||
DEFAULT_ADAPTIVE_MAX_TOKENS: ClassVar[int] = 32_768
|
||||
DEFAULT_MAX_TOKENS = 8192
|
||||
|
||||
|
|
@ -375,66 +369,32 @@ class AnthropicAdapter(APIAdapter):
|
|||
if last_block.get("type") in {"text", "image", "tool_result"}:
|
||||
last_block["cache_control"] = {"type": "ephemeral"}
|
||||
|
||||
# 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,
|
||||
payload: dict[str, Any],
|
||||
*,
|
||||
model_name: str,
|
||||
messages: list[dict[str, Any]],
|
||||
temperature: float,
|
||||
max_tokens: int | None,
|
||||
thinking: str,
|
||||
) -> 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:
|
||||
if not temperature_deprecated:
|
||||
payload["temperature"] = temperature
|
||||
if max_tokens is not None:
|
||||
payload["max_tokens"] = max_tokens
|
||||
else:
|
||||
payload["max_tokens"] = self.DEFAULT_MAX_TOKENS
|
||||
payload["max_tokens"] = (
|
||||
max_tokens if max_tokens is not None else self.DEFAULT_MAX_TOKENS
|
||||
)
|
||||
return
|
||||
|
||||
# Resolve effective level: use config, or fallback to "medium" when
|
||||
# forced by thinking content in history
|
||||
effective_level = thinking_level if thinking_level != "off" else "medium"
|
||||
|
||||
if self._is_adaptive_model(model_name):
|
||||
payload["thinking"] = {"type": "adaptive", "display": "summarized"}
|
||||
payload["output_config"] = {"effort": effective_level}
|
||||
default_max = self.DEFAULT_ADAPTIVE_MAX_TOKENS
|
||||
else:
|
||||
budget = self.THINKING_BUDGETS[effective_level]
|
||||
payload["thinking"] = {"type": "enabled", "budget_tokens": budget}
|
||||
default_max = budget + self.DEFAULT_MAX_TOKENS
|
||||
|
||||
if not temperature_deprecated:
|
||||
payload["temperature"] = 1
|
||||
payload["max_tokens"] = max_tokens if max_tokens is not None else default_max
|
||||
payload["thinking"] = {"type": "adaptive", "display": "summarized"}
|
||||
payload["output_config"] = {"effort": effective_level}
|
||||
payload["max_tokens"] = (
|
||||
max_tokens if max_tokens is not None else self.DEFAULT_ADAPTIVE_MAX_TOKENS
|
||||
)
|
||||
|
||||
def _build_payload(
|
||||
self,
|
||||
|
|
@ -442,7 +402,6 @@ class AnthropicAdapter(APIAdapter):
|
|||
model_name: str,
|
||||
system_prompt: str | None,
|
||||
messages: list[dict[str, Any]],
|
||||
temperature: float,
|
||||
tools: list[dict[str, Any]] | None,
|
||||
max_tokens: int | None,
|
||||
tool_choice: dict[str, Any] | None,
|
||||
|
|
@ -452,12 +411,7 @@ class AnthropicAdapter(APIAdapter):
|
|||
payload: dict[str, Any] = {"model": model_name, "messages": messages}
|
||||
|
||||
self._apply_thinking_config(
|
||||
payload,
|
||||
model_name=model_name,
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens,
|
||||
thinking=thinking,
|
||||
payload, messages=messages, max_tokens=max_tokens, thinking=thinking
|
||||
)
|
||||
|
||||
if system_blocks := self._build_system_blocks(system_prompt):
|
||||
|
|
@ -498,7 +452,6 @@ class AnthropicAdapter(APIAdapter):
|
|||
model_name=model_name,
|
||||
system_prompt=system_prompt,
|
||||
messages=converted_messages,
|
||||
temperature=temperature,
|
||||
tools=converted_tools,
|
||||
max_tokens=max_tokens,
|
||||
tool_choice=converted_tool_choice,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue