diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py index 0b05625f353..04b9834ca1f 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py @@ -300,9 +300,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): sent_first_chunk: bool = False sent_content_block_start: bool = False sent_content_block_finish: bool = False - current_content_block_type: Literal[ - "text", "tool_use", "thinking", "redacted_thinking" - ] = "text" + current_content_block_type: Literal["text", "tool_use", "thinking", "redacted_thinking"] = "text" sent_last_message: bool = False holding_chunk: ContentBlockDelta | None = None holding_stop_reason_chunk: MessageBlockDelta | None = None @@ -624,11 +622,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): processed_chunk = LiteLLMAnthropicMessagesAdapter().translate_streaming_openai_response_to_anthropic( response=chunk, current_content_block_index=self.current_content_block_index, - applied_edits=( - self.applied_edits - if is_final_chunk and not will_merge_into_held - else None - ), + applied_edits=(self.applied_edits if is_final_chunk and not will_merge_into_held else None), thinking_disabled=self.thinking_disabled, ) processed_chunk = self._with_refusal_stop_details(processed_chunk) @@ -890,11 +884,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): processed_chunk = LiteLLMAnthropicMessagesAdapter().translate_streaming_openai_response_to_anthropic( response=chunk, current_content_block_index=self.current_content_block_index, - applied_edits=( - self.applied_edits - if is_final_chunk and not will_merge_into_held - else None - ), + applied_edits=(self.applied_edits if is_final_chunk and not will_merge_into_held else None), thinking_disabled=self.thinking_disabled, ) processed_chunk = self._with_refusal_stop_details(processed_chunk) diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_thinking_disabled.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_thinking_disabled.py index ac0173a8bd0..c193ab221ec 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_thinking_disabled.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_handler_thinking_disabled.py @@ -39,9 +39,7 @@ MESSAGES = [{"role": "user", "content": "hello"}] "thinking_param,expected_thinking_disabled", THINKING_PARAMS, ) -async def test_async_handler_streaming_threads_thinking_disabled( - thinking_param, expected_thinking_disabled -): +async def test_async_handler_streaming_threads_thinking_disabled(thinking_param, expected_thinking_disabled): """Async handler, stream=True: ``thinking_disabled`` reaches the streaming adapter call.""" with ( @@ -55,9 +53,7 @@ async def test_async_handler_streaming_threads_thinking_disabled( return_value=({}, {}), ), patch("litellm.acompletion", return_value=MagicMock()), - patch( - "litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER" - ) as mock_adapter, + patch("litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER") as mock_adapter, ): mock_adapter.translate_completion_output_params_streaming.return_value = iter([]) await LiteLLMMessagesToCompletionTransformationHandler.async_anthropic_messages_handler( @@ -67,12 +63,10 @@ async def test_async_handler_streaming_threads_thinking_disabled( stream=True, thinking=thinking_param, ) - call_kwargs = ( - mock_adapter.translate_completion_output_params_streaming.call_args.kwargs + call_kwargs = mock_adapter.translate_completion_output_params_streaming.call_args.kwargs + assert call_kwargs.get("thinking_disabled") is expected_thinking_disabled, ( + f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" ) - assert ( - call_kwargs.get("thinking_disabled") is expected_thinking_disabled - ), f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" # --------------------------------------------------------------------------- @@ -84,9 +78,7 @@ async def test_async_handler_streaming_threads_thinking_disabled( "thinking_param,expected_thinking_disabled", THINKING_PARAMS, ) -async def test_async_handler_non_streaming_threads_thinking_disabled( - thinking_param, expected_thinking_disabled -): +async def test_async_handler_non_streaming_threads_thinking_disabled(thinking_param, expected_thinking_disabled): """Async handler, stream=False: ``thinking_disabled`` reaches the non-streaming adapter call.""" with ( @@ -100,9 +92,7 @@ async def test_async_handler_non_streaming_threads_thinking_disabled( return_value=({}, {}), ), patch("litellm.acompletion", return_value=MagicMock()), - patch( - "litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER" - ) as mock_adapter, + patch("litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER") as mock_adapter, ): mock_adapter.translate_completion_output_params.return_value = MagicMock() await LiteLLMMessagesToCompletionTransformationHandler.async_anthropic_messages_handler( @@ -113,9 +103,9 @@ async def test_async_handler_non_streaming_threads_thinking_disabled( thinking=thinking_param, ) call_kwargs = mock_adapter.translate_completion_output_params.call_args.kwargs - assert ( - call_kwargs.get("thinking_disabled") is expected_thinking_disabled - ), f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" + assert call_kwargs.get("thinking_disabled") is expected_thinking_disabled, ( + f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" + ) # --------------------------------------------------------------------------- @@ -127,9 +117,7 @@ async def test_async_handler_non_streaming_threads_thinking_disabled( "thinking_param,expected_thinking_disabled", THINKING_PARAMS, ) -def test_sync_handler_streaming_threads_thinking_disabled( - thinking_param, expected_thinking_disabled -): +def test_sync_handler_streaming_threads_thinking_disabled(thinking_param, expected_thinking_disabled): """Sync handler, stream=True: ``thinking_disabled`` reaches the streaming adapter call. @@ -143,9 +131,7 @@ def test_sync_handler_streaming_threads_thinking_disabled( return_value=({}, {}), ), patch("litellm.completion", return_value=MagicMock()), - patch( - "litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER" - ) as mock_adapter, + patch("litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER") as mock_adapter, ): mock_adapter.translate_completion_output_params_streaming.return_value = iter([]) LiteLLMMessagesToCompletionTransformationHandler.anthropic_messages_handler( @@ -155,12 +141,10 @@ def test_sync_handler_streaming_threads_thinking_disabled( stream=True, thinking=thinking_param, ) - call_kwargs = ( - mock_adapter.translate_completion_output_params_streaming.call_args.kwargs + call_kwargs = mock_adapter.translate_completion_output_params_streaming.call_args.kwargs + assert call_kwargs.get("thinking_disabled") is expected_thinking_disabled, ( + f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" ) - assert ( - call_kwargs.get("thinking_disabled") is expected_thinking_disabled - ), f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" # --------------------------------------------------------------------------- @@ -172,9 +156,7 @@ def test_sync_handler_streaming_threads_thinking_disabled( "thinking_param,expected_thinking_disabled", THINKING_PARAMS, ) -def test_sync_handler_non_streaming_threads_thinking_disabled( - thinking_param, expected_thinking_disabled -): +def test_sync_handler_non_streaming_threads_thinking_disabled(thinking_param, expected_thinking_disabled): """Sync handler, stream=False: ``thinking_disabled`` reaches the non-streaming adapter call. @@ -188,9 +170,7 @@ def test_sync_handler_non_streaming_threads_thinking_disabled( return_value=({}, {}), ), patch("litellm.completion", return_value=MagicMock()), - patch( - "litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER" - ) as mock_adapter, + patch("litellm.llms.anthropic.experimental_pass_through.adapters.handler.ANTHROPIC_ADAPTER") as mock_adapter, ): mock_adapter.translate_completion_output_params.return_value = MagicMock() LiteLLMMessagesToCompletionTransformationHandler.anthropic_messages_handler( @@ -201,6 +181,6 @@ def test_sync_handler_non_streaming_threads_thinking_disabled( thinking=thinking_param, ) call_kwargs = mock_adapter.translate_completion_output_params.call_args.kwargs - assert ( - call_kwargs.get("thinking_disabled") is expected_thinking_disabled - ), f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" + assert call_kwargs.get("thinking_disabled") is expected_thinking_disabled, ( + f"thinking={thinking_param!r}: expected thinking_disabled={expected_thinking_disabled}" + )