From ad90871ad6bbba6503e406590dc76d2d3ddb59a5 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 4 Apr 2025 12:37:34 -0700 Subject: [PATCH] fix(factory.py): don't pass cache control if not set bedrock invoke does not support this --- litellm/litellm_core_utils/prompt_templates/factory.py | 9 +++++---- litellm/types/llms/anthropic.py | 2 +- tests/llm_translation/test_prompt_factory.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 15c8cc275c..e8d8456ed7 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -1254,7 +1254,6 @@ def convert_function_to_anthropic_tool_invoke( id=str(uuid.uuid4()), name=_name, input=json.loads(_arguments) if _arguments else {}, - cache_control=None, ) ] return anthropic_tool_invoke @@ -1309,14 +1308,16 @@ def convert_to_anthropic_tool_invoke( _anthropic_tool_use_param = AnthropicMessagesToolUseParam( type="tool_use", - id=get_attribute_or_key(tool, "id"), - name=get_attribute_or_key(get_attribute_or_key(tool, "function"), "name"), + id=cast(str, get_attribute_or_key(tool, "id")), + name=cast( + str, + get_attribute_or_key(get_attribute_or_key(tool, "function"), "name"), + ), input=json.loads( get_attribute_or_key( get_attribute_or_key(tool, "function"), "arguments" ) ), - cache_control=None, ) _content_element = add_cache_control_to_content( diff --git a/litellm/types/llms/anthropic.py b/litellm/types/llms/anthropic.py index 003c0bc62d..781d3caa9f 100644 --- a/litellm/types/llms/anthropic.py +++ b/litellm/types/llms/anthropic.py @@ -52,7 +52,7 @@ class AnthropicMessagesTextParam(TypedDict, total=False): cache_control: Optional[Union[dict, ChatCompletionCachedContent]] -class AnthropicMessagesToolUseParam(TypedDict): +class AnthropicMessagesToolUseParam(TypedDict, total=False): type: Required[Literal["tool_use"]] id: str name: str diff --git a/tests/llm_translation/test_prompt_factory.py b/tests/llm_translation/test_prompt_factory.py index 5ccc2e3aac..f994acc330 100644 --- a/tests/llm_translation/test_prompt_factory.py +++ b/tests/llm_translation/test_prompt_factory.py @@ -345,7 +345,7 @@ def test_anthropic_cache_controls_tool_calls_pt(): assert translated_messages[1]["role"] == "assistant" for content_item in translated_messages[1]["content"]: if content_item["type"] == "tool_use": - assert content_item["cache_control"] is None + assert "cache_control" not in content_item assert content_item["name"] == "get_weather" assert translated_messages[2]["role"] == "user"