mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
Merge 866cf64a45 into ce25856424
This commit is contained in:
commit
dd21d9a54e
2 changed files with 34 additions and 3 deletions
|
|
@ -305,9 +305,13 @@ class LiteLLMAnthropicToResponsesAPIAdapter:
|
|||
elif isinstance(inner, str):
|
||||
output_text = inner
|
||||
elif isinstance(inner, list):
|
||||
parts = [
|
||||
c.get("text", "") for c in inner if isinstance(c, dict) and c.get("type") == "text"
|
||||
]
|
||||
parts = (
|
||||
c.get("text", "")
|
||||
if c.get("type") == "text"
|
||||
else f"[Loaded tool: {c.get('tool_name', '')}]"
|
||||
for c in inner
|
||||
if isinstance(c, dict) and c.get("type") in {"text", "tool_reference"}
|
||||
)
|
||||
output_text = "\n".join(parts)
|
||||
image_candidates = tuple(
|
||||
self._translate_anthropic_image_source_to_url(c.get("source"))
|
||||
|
|
|
|||
|
|
@ -481,6 +481,33 @@ class TestTranslateMessagesToResponsesInput:
|
|||
result = _translate_messages(messages)
|
||||
assert result[0]["output"] == "Line 1\nLine 2"
|
||||
|
||||
def test_user_tool_result_list_content_preserves_tool_references(self):
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "tool_result",
|
||||
"tool_use_id": "call_search",
|
||||
"content": [
|
||||
{"type": "text", "text": "Available:"},
|
||||
{"type": "tool_reference", "tool_name": "get_weather"},
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
|
||||
result = _translate_messages(messages)
|
||||
|
||||
assert result == [
|
||||
{
|
||||
"type": "function_call_output",
|
||||
"call_id": "call_search",
|
||||
"output": "Available:\n[Loaded tool: get_weather]",
|
||||
}
|
||||
]
|
||||
|
||||
def test_user_tool_result_null_content(self):
|
||||
"""tool_result with null content becomes empty string output."""
|
||||
messages = [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue