From d87078c32dbe4efbfffdd1775b233e69c185249a Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 8 Aug 2024 17:32:55 -0700 Subject: [PATCH] fix(anthropic.py): fix translation --- litellm/llms/anthropic.py | 6 +++--- litellm/tests/test_anthropic_completion.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/litellm/llms/anthropic.py b/litellm/llms/anthropic.py index 20c74fb3d50..6f05aa226e0 100644 --- a/litellm/llms/anthropic.py +++ b/litellm/llms/anthropic.py @@ -223,6 +223,9 @@ class AnthropicConfig: for m in messages: user_message: Optional[ChatCompletionUserMessage] = None tool_message_list: List[ChatCompletionToolMessage] = [] + new_user_content_list: List[ + Union[ChatCompletionTextObject, ChatCompletionImageObject] + ] = [] ## USER MESSAGE ## if m["role"] == "user": ## translate user message @@ -231,9 +234,6 @@ class AnthropicConfig: role="user", content=m["content"] ) elif isinstance(m["content"], list): - new_user_content_list: List[ - Union[ChatCompletionTextObject, ChatCompletionImageObject] - ] = [] for content in m["content"]: if content["type"] == "text": text_obj = ChatCompletionTextObject( diff --git a/litellm/tests/test_anthropic_completion.py b/litellm/tests/test_anthropic_completion.py index 20260556ec2..b3c4745c990 100644 --- a/litellm/tests/test_anthropic_completion.py +++ b/litellm/tests/test_anthropic_completion.py @@ -275,4 +275,4 @@ def test_anthropic_tool_calling_translation(): print(translated_params["messages"]) assert len(translated_params["messages"]) > 0 - assert translated_params["messages"][1]["role"] == "user" + assert translated_params["messages"][0]["role"] == "user"