fix(factory.py): don't pass cache control if not set

bedrock invoke does not support this
This commit is contained in:
Krrish Dholakia
2025-04-04 12:37:34 -07:00
parent e67d16d5bd
commit ad90871ad6
3 changed files with 7 additions and 6 deletions
@@ -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(
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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"