mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
Merge 2dfa7cf7c0 into e768ad55ce
This commit is contained in:
commit
4905392367
2 changed files with 49 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 #
|
||||
# ------------------------------------------------------------------ #
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue