test_anthropic_prompt_caching_middleware_initialization() — langchain Function Reference
Architecture documentation for the test_anthropic_prompt_caching_middleware_initialization() function in test_prompt_caching.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9f6c0b0a_18cf_db24_ef58_e35a0e194dad["test_anthropic_prompt_caching_middleware_initialization()"] 80b9bbd1_b825_9778_a36c_351fbf1d2478["test_prompt_caching.py"] 9f6c0b0a_18cf_db24_ef58_e35a0e194dad -->|defined in| 80b9bbd1_b825_9778_a36c_351fbf1d2478 style 9f6c0b0a_18cf_db24_ef58_e35a0e194dad fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py lines 58–101
def test_anthropic_prompt_caching_middleware_initialization() -> None:
"""Test AnthropicPromptCachingMiddleware initialization."""
# Test with custom values
middleware = AnthropicPromptCachingMiddleware(
type="ephemeral", ttl="1h", min_messages_to_cache=5
)
assert middleware.type == "ephemeral"
assert middleware.ttl == "1h"
assert middleware.min_messages_to_cache == 5
# Test with default values
middleware = AnthropicPromptCachingMiddleware()
assert middleware.type == "ephemeral"
assert middleware.ttl == "5m"
assert middleware.min_messages_to_cache == 0
# Create a mock ChatAnthropic instance
mock_chat_anthropic = MagicMock(spec=ChatAnthropic)
fake_request = ModelRequest(
model=mock_chat_anthropic,
messages=[HumanMessage("Hello")],
system_prompt=None,
tool_choice=None,
tools=[],
response_format=None,
state={"messages": [HumanMessage("Hello")]},
runtime=cast(Runtime, object()),
model_settings={},
)
modified_request: ModelRequest | None = None
def mock_handler(req: ModelRequest) -> ModelResponse:
nonlocal modified_request
modified_request = req
return ModelResponse(result=[AIMessage(content="mock response")])
middleware.wrap_model_call(fake_request, mock_handler)
# Check that model_settings were passed through via the request
assert modified_request is not None
assert modified_request.model_settings == {
"cache_control": {"type": "ephemeral", "ttl": "5m"}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does test_anthropic_prompt_caching_middleware_initialization() do?
test_anthropic_prompt_caching_middleware_initialization() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py.
Where is test_anthropic_prompt_caching_middleware_initialization() defined?
test_anthropic_prompt_caching_middleware_initialization() is defined in libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py at line 58.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free