mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix(anthropic-adapter): keep disabled-thinking reasoning_effort a plain string
Guard against reasoning_auto_summary wrapping "none" into a dict when thinking is disabled — there's no reasoning trace to summarize, and non-Claude providers (e.g. Fireworks) expect reasoning_effort as a plain string.
This commit is contained in:
parent
b3e27a0bc3
commit
9da21f38a9
2 changed files with 24 additions and 1 deletions
|
|
@ -989,12 +989,18 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
if not reasoning_effort:
|
||||
return
|
||||
|
||||
thinking_type = thinking.get("type") if isinstance(thinking, dict) else None
|
||||
|
||||
# For adaptive thinking, override with output_config.effort if available
|
||||
if isinstance(thinking, dict) and thinking.get("type") == "adaptive":
|
||||
if thinking_type == "adaptive":
|
||||
output_config = anthropic_message_request.get("output_config")
|
||||
if isinstance(output_config, dict) and output_config.get("effort"):
|
||||
reasoning_effort = output_config["effort"]
|
||||
|
||||
if thinking_type == "disabled":
|
||||
new_kwargs["reasoning_effort"] = reasoning_effort
|
||||
return
|
||||
|
||||
summary = thinking.get("summary") if isinstance(thinking, dict) else None
|
||||
auto_summary = is_reasoning_auto_summary_enabled()
|
||||
if summary:
|
||||
|
|
|
|||
|
|
@ -1593,6 +1593,23 @@ def test_thinking_disabled_translated_to_reasoning_effort_none_for_non_claude_mo
|
|||
assert new_kwargs["reasoning_effort"] == "none"
|
||||
|
||||
|
||||
def test_thinking_disabled_stays_plain_string_when_auto_summary_enabled():
|
||||
import litellm
|
||||
|
||||
adapter = LiteLLMAnthropicMessagesAdapter()
|
||||
thinking = {"type": "disabled"}
|
||||
|
||||
original = litellm.reasoning_auto_summary
|
||||
try:
|
||||
litellm.reasoning_auto_summary = True
|
||||
new_kwargs = {"model": CACHE_CONTROL_NON_ANTHROPIC_MODEL}
|
||||
adapter._translate_thinking_to_openai(cast(Any, {"thinking": thinking}), cast(Any, new_kwargs))
|
||||
finally:
|
||||
litellm.reasoning_auto_summary = original
|
||||
|
||||
assert new_kwargs["reasoning_effort"] == "none"
|
||||
|
||||
|
||||
def test_stop_sequences_translated_to_stop_for_non_claude_model():
|
||||
from litellm.types.llms.anthropic import AnthropicMessagesRequest
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue