This commit is contained in:
Deepanshu Pal 2026-10-03 20:11:58 +08:00 • committed by GitHub
commit 4905392367
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 2 deletions

View file

@ -87,7 +87,13 @@ def handle_messages_with_content_list_to_str_conversion(
"""
for message in messages:
texts = convert_content_list_to_str(message=message)
if texts:
content = message.get("content")
is_text_only_list = (
isinstance(content, list)
and bool(content)
and all(isinstance(part, dict) and part.get("type") == "text" for part in content)
)
if texts or is_text_only_list:
message["content"] = texts
return messages

View file

@ -7,7 +7,6 @@ Moonshot AI is an OpenAI-compatible provider with minor customizations.
from unittest.mock import patch
import pytest
import litellm
@ -433,6 +432,48 @@ class TestMoonshotConfig:
assert isinstance(result["messages"][0]["content"], str)
assert result["messages"][0]["content"] == "Hello, how are you?"
def test_transform_messages_flattens_empty_text_for_tool_call(self):
"""Moonshot accepts an empty string, but rejects an empty text part."""
config = MoonshotChatConfig()
messages = [
{
"role": "assistant",
"content": [{"type": "text", "text": ""}],
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {"name": "foo", "arguments": "{}"},
}
],
}
]
result = config.transform_request(
model="moonshot-v1-8k",
messages=messages,
optional_params={},
litellm_params={},
headers={},
)
assert result["messages"][0]["content"] == ""
def test_transform_messages_preserves_empty_content_list(self):
"""An empty list has no text parts to flatten."""
config = MoonshotChatConfig()
messages = [{"role": "assistant", "content": [], "tool_calls": []}]
result = config.transform_request(
model="moonshot-v1-8k",
messages=messages,
optional_params={},
litellm_params={},
headers={},
)
assert result["messages"][0]["content"] == []
# ------------------------------------------------------------------ #
# Tests for fill_reasoning_content #
# ------------------------------------------------------------------ #