From 64c916b37b13fe4b95b1b22b7947f9ecabb5dca8 Mon Sep 17 00:00:00 2001 From: ZeroAurora Date: Thu, 19 Feb 2026 07:30:13 +0000 Subject: [PATCH] fix: remove list-to-str transformation from dashscope --- litellm/llms/dashscope/chat/transformation.py | 7 ---- .../test_dashscope_chat_transformation.py | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/litellm/llms/dashscope/chat/transformation.py b/litellm/llms/dashscope/chat/transformation.py index 155d8c9ec2..cc5cf99182 100644 --- a/litellm/llms/dashscope/chat/transformation.py +++ b/litellm/llms/dashscope/chat/transformation.py @@ -4,9 +4,6 @@ Translates from OpenAI's `/v1/chat/completions` to DashScope's `/v1/chat/complet from typing import Any, Coroutine, List, Literal, Optional, Tuple, Union, overload -from litellm.litellm_core_utils.prompt_templates.common_utils import ( - handle_messages_with_content_list_to_str_conversion, -) from litellm.secret_managers.main import get_secret_str from litellm.types.llms.openai import AllMessageValues @@ -32,10 +29,6 @@ class DashScopeChatConfig(OpenAIGPTConfig): def _transform_messages( self, messages: List[AllMessageValues], model: str, is_async: bool = False ) -> Union[List[AllMessageValues], Coroutine[Any, Any, List[AllMessageValues]]]: - """ - DashScope does not support content in list format. - """ - messages = handle_messages_with_content_list_to_str_conversion(messages) if is_async: return super()._transform_messages( messages=messages, model=model, is_async=True diff --git a/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py b/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py index ff2302749f..b5f656c71f 100644 --- a/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py +++ b/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py @@ -12,6 +12,7 @@ sys.path.insert( 0, os.path.abspath("../../../../..") ) # Adds the parent directory to the system path +from litellm.types.llms.openai import AllMessageValues import pytest import litellm @@ -111,3 +112,35 @@ class TestDashScopeConfig: # Check for specific content in the response assert "```python" in response.choices[0].message.content assert "Hey from LiteLLM" in response.choices[0].message.content + + def test_dashscope_no_longer_transforms_content_list(self): + """ + Test that DashScopeChatConfig does not transform content lists to strings. + This ensures that the transformation logic specific to content lists is not applied, + as DashScope should handle content in list format natively. + """ + config = DashScopeChatConfig() + + # Create a message with content in list format + messages: list[AllMessageValues] = [ + { + "role": "user", + "content": [ + {"type": "text", "text": "Hello"}, + {"type": "text", "text": "World"}, + ], + } + ] + + # Call the _transform_messages method directly + transformed_messages = config._transform_messages( + messages=messages, model="qwen-turbo", is_async=False + ) + + # Verify that the content is still in list format and has not been transformed to a string + assert isinstance(transformed_messages[0]["content"], list) + assert len(transformed_messages[0]["content"]) == 2 + assert transformed_messages[0]["content"][0]["type"] == "text" + assert transformed_messages[0]["content"][0]["text"] == "Hello" + assert transformed_messages[0]["content"][1]["type"] == "text" + assert transformed_messages[0]["content"][1]["text"] == "World"