fix: remove list-to-str transformation from dashscope

This commit is contained in:
ZeroAurora
2026-02-19 07:30:13 +00:00
parent 70d5281b52
commit 64c916b37b
2 changed files with 33 additions and 7 deletions
@@ -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
@@ -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"