Skip to content

Commit 56a8047

Browse files
ronakrmclaude
andcommitted
Address PR review comments
- Move CachePoint imports to top of test files (test_bedrock.py, test_huggingface.py) - Add documentation link for cacheable_types in anthropic.py Addresses feedback from @DouweM in PR #3363 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f088447 commit 56a8047

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

pydantic_ai_slim/pydantic_ai/models/anthropic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ def _add_cache_control_to_last_param(params: list[BetaContentBlockParam]) -> Non
696696
)
697697

698698
# Only certain types support cache_control
699+
# See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#what-can-be-cached
699700
cacheable_types = {'text', 'tool_use', 'server_tool_use', 'image', 'tool_result'}
700701
last_param = cast(dict[str, Any], params[-1]) # Cast to dict for mutation
701702
if last_param['type'] not in cacheable_types:

tests/models/test_bedrock.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pydantic_ai import (
1111
BinaryContent,
12+
CachePoint,
1213
DocumentUrl,
1314
FinalResultEvent,
1415
FunctionToolCallEvent,
@@ -1518,9 +1519,6 @@ async def test_cache_point_filtering():
15181519
"""Test that CachePoint is filtered out in Bedrock message mapping."""
15191520
from itertools import count
15201521

1521-
from pydantic_ai import CachePoint, UserPromptPart
1522-
from pydantic_ai.models.bedrock import BedrockConverseModel
1523-
15241522
# Test the static method directly
15251523
messages = await BedrockConverseModel._map_user_prompt(UserPromptPart(content=['text', CachePoint()]), count()) # pyright: ignore[reportPrivateUsage]
15261524
# CachePoint should be filtered out, message should still be valid

tests/models/test_huggingface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Agent,
3535
AudioUrl,
3636
BinaryContent,
37+
CachePoint,
3738
DocumentUrl,
3839
ImageUrl,
3940
ModelRequest,
@@ -1020,9 +1021,6 @@ async def test_hf_model_thinking_part_iter(allow_model_requests: None, huggingfa
10201021

10211022
async def test_cache_point_filtering():
10221023
"""Test that CachePoint is filtered out in HuggingFace message mapping."""
1023-
from pydantic_ai import CachePoint, UserPromptPart
1024-
from pydantic_ai.models.huggingface import HuggingFaceModel
1025-
10261024
# Test the static method directly
10271025
msg = await HuggingFaceModel._map_user_prompt(UserPromptPart(content=['text', CachePoint()])) # pyright: ignore[reportPrivateUsage]
10281026

0 commit comments

Comments
 (0)