The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: remove list-to-str transformation from dashscope
ZeroAurora64c916b37b13
diff --git a/litellm/llms/dashscope/chat/transformation.py b/litellm/llms/dashscope/chat/transformation.pyindex 155d8c9ec27..cc5cf991826 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/completfrom 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_strfrom 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=Truediff --git a/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py b/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.pyindex ff2302749f1..b5f656c71f8 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 AllMessageValuesimport pytestimport litellm@@ -111,3 +112,35 @@ class TestDashScopeConfig:# Check for specific content in the responseassert "```python" in response.choices[0].message.contentassert "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"