mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
fix: address Greptile review — assert mock called, add auto-summary check, format
This commit is contained in:
parent
a254ada5a7
commit
eb9f0005a9
4 changed files with 46 additions and 25 deletions
|
|
@ -443,7 +443,9 @@ def anthropic_messages_handler(
|
|||
)
|
||||
force_reasoning_effort = litellm_params.force_reasoning_effort
|
||||
if force_reasoning_effort:
|
||||
output_config = anthropic_messages_optional_request_params.get("output_config") or {}
|
||||
output_config = (
|
||||
anthropic_messages_optional_request_params.get("output_config") or {}
|
||||
)
|
||||
anthropic_messages_optional_request_params["output_config"] = {
|
||||
**output_config,
|
||||
"effort": force_reasoning_effort,
|
||||
|
|
@ -451,7 +453,9 @@ def anthropic_messages_handler(
|
|||
# Effort alone does not trigger reasoning — force-enable thinking too
|
||||
thinking = anthropic_messages_optional_request_params.get("thinking")
|
||||
if not isinstance(thinking, dict) or thinking.get("type") == "disabled":
|
||||
anthropic_messages_optional_request_params["thinking"] = {"type": "adaptive"}
|
||||
anthropic_messages_optional_request_params["thinking"] = {
|
||||
"type": "adaptive"
|
||||
}
|
||||
|
||||
return base_llm_http_handler.anthropic_messages_handler(
|
||||
model=model,
|
||||
|
|
|
|||
|
|
@ -99,10 +99,17 @@ def _build_responses_kwargs(
|
|||
if force_reasoning_effort:
|
||||
reasoning = responses_kwargs.get("reasoning")
|
||||
if isinstance(reasoning, dict):
|
||||
responses_kwargs["reasoning"] = {**reasoning, "effort": force_reasoning_effort}
|
||||
responses_kwargs["reasoning"] = {
|
||||
**reasoning,
|
||||
"effort": force_reasoning_effort,
|
||||
}
|
||||
else:
|
||||
responses_kwargs["reasoning"] = {
|
||||
**({"summary": "detailed"} if is_reasoning_auto_summary_enabled() else {}),
|
||||
**(
|
||||
{"summary": "detailed"}
|
||||
if is_reasoning_auto_summary_enabled()
|
||||
else {}
|
||||
),
|
||||
"effort": force_reasoning_effort,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -868,7 +868,18 @@ def responses(
|
|||
if isinstance(reasoning, dict):
|
||||
reasoning = {**reasoning, "effort": force_reasoning_effort}
|
||||
else:
|
||||
reasoning = {"effort": force_reasoning_effort}
|
||||
from litellm.llms.anthropic.experimental_pass_through.utils import (
|
||||
is_reasoning_auto_summary_enabled,
|
||||
)
|
||||
|
||||
reasoning = {
|
||||
**(
|
||||
{"summary": "detailed"}
|
||||
if is_reasoning_auto_summary_enabled()
|
||||
else {}
|
||||
),
|
||||
"effort": force_reasoning_effort,
|
||||
}
|
||||
local_vars["reasoning"] = reasoning
|
||||
# Get ResponsesAPIOptionalRequestParams with only valid parameters
|
||||
response_api_optional_params: ResponsesAPIOptionalRequestParams = (
|
||||
|
|
|
|||
|
|
@ -269,14 +269,13 @@ class TestAnthropicMessagesForceReasoningEffort:
|
|||
except (ValueError, TypeError, AttributeError):
|
||||
pass
|
||||
|
||||
if mock_handler.called:
|
||||
call_kwargs = mock_handler.call_args
|
||||
optional_params = call_kwargs.kwargs.get(
|
||||
"anthropic_messages_optional_request_params", {}
|
||||
)
|
||||
assert optional_params.get("output_config", {}).get("effort") == "high"
|
||||
# thinking should be enabled when not already set
|
||||
assert optional_params.get("thinking") == {"type": "adaptive"}
|
||||
assert mock_handler.called, "mock handler was not called — test is a no-op"
|
||||
call_kwargs = mock_handler.call_args
|
||||
optional_params = call_kwargs.kwargs.get(
|
||||
"anthropic_messages_optional_request_params", {}
|
||||
)
|
||||
assert optional_params.get("output_config", {}).get("effort") == "high"
|
||||
assert optional_params.get("thinking") == {"type": "adaptive"}
|
||||
|
||||
def test_force_preserves_existing_thinking_config(self):
|
||||
"""force_reasoning_effort should not override existing enabled thinking config."""
|
||||
|
|
@ -299,18 +298,18 @@ class TestAnthropicMessagesForceReasoningEffort:
|
|||
except (ValueError, TypeError, AttributeError):
|
||||
pass
|
||||
|
||||
if mock_handler.called:
|
||||
call_kwargs = mock_handler.call_args
|
||||
optional_params = call_kwargs.kwargs.get(
|
||||
"anthropic_messages_optional_request_params", {}
|
||||
)
|
||||
assert optional_params.get("output_config", {}).get("effort") == "high"
|
||||
# Pre-existing enabled thinking should be preserved
|
||||
thinking = optional_params.get("thinking", {})
|
||||
assert (
|
||||
thinking.get("type") != "adaptive"
|
||||
or thinking.get("type") == "enabled"
|
||||
)
|
||||
assert mock_handler.called, "mock handler was not called — test is a no-op"
|
||||
call_kwargs = mock_handler.call_args
|
||||
optional_params = call_kwargs.kwargs.get(
|
||||
"anthropic_messages_optional_request_params", {}
|
||||
)
|
||||
assert optional_params.get("output_config", {}).get("effort") == "high"
|
||||
# Pre-existing enabled thinking should be preserved
|
||||
thinking = optional_params.get("thinking", {})
|
||||
assert (
|
||||
thinking.get("type") != "adaptive"
|
||||
or thinking.get("type") == "enabled"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue