Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(anthropic.py): fix translation

Krrish Dholakiad87078c32dbe
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"