Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ def _translate_adaptive_effort_for_non_adaptive_model(

if capped_thinking is not None:
optional_params["thinking"] = capped_thinking
if capped_thinking.get("type") == "enabled" and optional_params.get("temperature") != 1:
optional_params.pop("temperature", None)
Comment on lines +367 to +368

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The condition optional_params.get("temperature") != 1 evaluates to True when temperature is absent (None != 1), so pop("temperature", None) is called on every legacy-thinking translation even when no temperature was set. The pop default prevents any error, but the intent — "only strip an explicitly-provided non-1 temperature" — is clearer with an explicit membership check.

Suggested change
if capped_thinking.get("type") == "enabled" and optional_params.get("temperature") != 1:
optional_params.pop("temperature", None)
if (
capped_thinking.get("type") == "enabled"
and "temperature" in optional_params
and optional_params["temperature"] != 1
):
optional_params.pop("temperature")

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

else:
verbose_logger.warning(DROP_UNSUPPORTED_ADAPTIVE_EFFORT_WARNING, model)
optional_params.pop("thinking", None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ def test_effort_translated_to_legacy_thinking_for_haiku_4_5():
assert "output_config" not in result


def test_non_1_temperature_dropped_for_legacy_thinking_on_haiku_4_5():
result = _transform(
"claude-haiku-4-5",
{**_claude_code_payload(effort="medium"), "temperature": 0},
)

assert result["thinking"] == {
"type": "enabled",
"budget_tokens": DEFAULT_REASONING_EFFORT_MEDIUM_THINKING_BUDGET,
}
assert "temperature" not in result


def test_temperature_1_preserved_for_legacy_thinking_on_haiku_4_5():
result = _transform(
"claude-haiku-4-5",
{**_claude_code_payload(effort="medium"), "temperature": 1},
)

assert result["thinking"] == {
"type": "enabled",
"budget_tokens": DEFAULT_REASONING_EFFORT_MEDIUM_THINKING_BUDGET,
}
assert result["temperature"] == 1


def test_effort_high_maps_to_high_budget_for_sonnet_4_5():
result = _transform("claude-sonnet-4-5", _claude_code_payload(effort="high"))

Expand All @@ -63,6 +89,17 @@ def test_adaptive_effort_passes_through_untouched_for_4_6():
assert result["output_config"] == {"effort": "high"}


def test_non_1_temperature_preserved_for_adaptive_thinking_on_4_6():
result = _transform(
"claude-sonnet-4-6",
{**_claude_code_payload(effort="high"), "temperature": 0},
)

assert result["thinking"] == {"type": "adaptive"}
assert result["output_config"] == {"effort": "high"}
assert result["temperature"] == 0


def test_thinking_and_effort_dropped_for_non_reasoning_model():
"""A model with no reasoning support cannot take thinking or effort, so both are
silently dropped (no drop_params required) so the request still succeeds."""
Expand Down
Loading