From cddee1de97500054a0219f15e0678e09b3e1c099 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 12 Jan 2026 17:31:43 +0530 Subject: [PATCH] refactor: fix linting error --- .../bedrock/chat/converse_transformation.py | 87 ++++++++++++++----- ...odel_prices_and_context_window_backup.json | 1 + 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py index 3b7bfd262ac..59590e464fc 100644 --- a/litellm/llms/bedrock/chat/converse_transformation.py +++ b/litellm/llms/bedrock/chat/converse_transformation.py @@ -339,6 +339,55 @@ class AmazonConverseConfig(BaseConfig): } } + def _handle_reasoning_effort_parameter( + self, model: str, reasoning_effort: str, optional_params: dict + ) -> None: + """ + Handle the reasoning_effort parameter based on the model type. + + Different model families handle reasoning effort differently: + - GPT-OSS models: Keep reasoning_effort as-is (passed to additionalModelRequestFields) + - Nova Lite 2 models: Transform to reasoningConfig structure + - Other models (Anthropic, etc.): Convert to thinking parameter + + Args: + model: The model identifier + reasoning_effort: The reasoning effort value + optional_params: Dictionary of optional parameters to update in-place + + Examples: + >>> config = AmazonConverseConfig() + >>> params = {} + >>> config._handle_reasoning_effort_parameter("gpt-oss-model", "high", params) + >>> params + {'reasoning_effort': 'high'} + + >>> params = {} + >>> config._handle_reasoning_effort_parameter("amazon.nova-2-lite-v1:0", "high", params) + >>> params + {'reasoningConfig': {'type': 'enabled', 'maxReasoningEffort': 'high'}} + + >>> params = {} + >>> config._handle_reasoning_effort_parameter("anthropic.claude-3", "high", params) + >>> params + {'thinking': {'type': 'enabled', 'budget_tokens': 10000}} + """ + if "gpt-oss" in model: + # GPT-OSS models: keep reasoning_effort as-is + # It will be passed through to additionalModelRequestFields + optional_params["reasoning_effort"] = reasoning_effort + elif self._is_nova_lite_2_model(model): + # Nova Lite 2 models: transform to reasoningConfig + reasoning_config = self._transform_reasoning_effort_to_reasoning_config( + reasoning_effort + ) + optional_params.update(reasoning_config) + else: + # Anthropic and other models: convert to thinking parameter + optional_params["thinking"] = AnthropicConfig._map_reasoning_effort( + reasoning_effort + ) + def get_supported_openai_params(self, model: str) -> List[str]: from litellm.utils import supports_function_calling @@ -658,21 +707,9 @@ class AmazonConverseConfig(BaseConfig): if param == "thinking": optional_params["thinking"] = value elif param == "reasoning_effort" and isinstance(value, str): - if "gpt-oss" in model: - # GPT-OSS models: keep reasoning_effort as-is - # It will be passed through to additionalModelRequestFields - optional_params["reasoning_effort"] = value - elif self._is_nova_lite_2_model(model): - # Nova Lite 2 models: transform to reasoningConfig - reasoning_config = ( - self._transform_reasoning_effort_to_reasoning_config(value) - ) - optional_params.update(reasoning_config) - else: - # Anthropic and other models: convert to thinking parameter - optional_params["thinking"] = AnthropicConfig._map_reasoning_effort( - value - ) + self._handle_reasoning_effort_parameter( + model=model, reasoning_effort=value, optional_params=optional_params + ) if param == "requestMetadata": if value is not None and isinstance(value, dict): self._validate_request_metadata(value) # type: ignore @@ -695,10 +732,7 @@ class AmazonConverseConfig(BaseConfig): ) final_is_thinking_enabled = self.is_thinking_enabled(optional_params) - if ( - final_is_thinking_enabled - and "tool_choice" in optional_params - ): + if final_is_thinking_enabled and "tool_choice" in optional_params: tool_choice_block = optional_params["tool_choice"] if isinstance(tool_choice_block, dict): if "any" in tool_choice_block or "tool" in tool_choice_block: @@ -922,20 +956,22 @@ class AmazonConverseConfig(BaseConfig): inference_params = { k: v for k, v in inference_params.items() if k in total_supported_params } - + # Only set the topK value in for models that support it additional_request_params.update( self._handle_top_k_value(model, inference_params) ) - + # Filter out internal/MCP-related parameters that shouldn't be sent to the API # These are LiteLLM internal parameters, not API parameters additional_request_params = filter_internal_params(additional_request_params) - + # Filter out non-serializable objects (exceptions, callables, logging objects, etc.) # from additional_request_params to prevent JSON serialization errors # This filters: Exception objects, callable objects (functions), Logging objects, etc. - additional_request_params = filter_exceptions_from_params(additional_request_params) + additional_request_params = filter_exceptions_from_params( + additional_request_params + ) return inference_params, additional_request_params, request_metadata @@ -960,7 +996,10 @@ class AmazonConverseConfig(BaseConfig): if original_tools: for tool in original_tools: tool_type = tool.get("type", "") - if tool_type in ("tool_search_tool_regex_20251119", "tool_search_tool_bm25_20251119"): + if tool_type in ( + "tool_search_tool_regex_20251119", + "tool_search_tool_bm25_20251119", + ): # Tool search not supported in Converse API - skip it continue filtered_tools.append(tool) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index 2f34d2a7d3d..de341834694 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -12532,6 +12532,7 @@ "deprecation_date": "2026-01-15", "cache_read_input_token_cost": 7.5e-08, "input_cost_per_audio_token": 1e-06, + "input_cost_per_image_token": 3e-07, "input_cost_per_token": 3e-07, "litellm_provider": "vertex_ai-language-models", "max_audio_length_hours": 8.4,