test__format_messages_with_cache_control() — langchain Function Reference
Architecture documentation for the test__format_messages_with_cache_control() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4735cced_eb30_5707_cec3_90b74187caf5["test__format_messages_with_cache_control()"] 18428dc5_a41b_90c6_88ad_615296ee3311["test_chat_models.py"] 4735cced_eb30_5707_cec3_90b74187caf5 -->|defined in| 18428dc5_a41b_90c6_88ad_615296ee3311 style 4735cced_eb30_5707_cec3_90b74187caf5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/tests/unit_tests/test_chat_models.py lines 855–1105
def test__format_messages_with_cache_control() -> None:
messages = [
SystemMessage(
[
{"type": "text", "text": "foo", "cache_control": {"type": "ephemeral"}},
],
),
HumanMessage(
[
{"type": "text", "text": "foo", "cache_control": {"type": "ephemeral"}},
{
"type": "text",
"text": "foo",
},
],
),
]
expected_system = [
{"type": "text", "text": "foo", "cache_control": {"type": "ephemeral"}},
]
expected_messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "foo", "cache_control": {"type": "ephemeral"}},
{"type": "text", "text": "foo"},
],
},
]
actual_system, actual_messages = _format_messages(messages)
assert expected_system == actual_system
assert expected_messages == actual_messages
# Test standard multi-modal format (v0)
messages = [
HumanMessage(
[
{
"type": "text",
"text": "Summarize this document:",
},
{
"type": "file",
"source_type": "base64",
"mime_type": "application/pdf",
"data": "<base64 data>",
"cache_control": {"type": "ephemeral"},
},
],
),
]
actual_system, actual_messages = _format_messages(messages)
assert actual_system is None
expected_messages = [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Summarize this document:",
},
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "<base64 data>",
},
"cache_control": {"type": "ephemeral"},
},
],
},
]
assert actual_messages == expected_messages
# Test standard multi-modal format (v1)
messages = [
HumanMessage(
[
{
"type": "text",
Domain
Subdomains
Source
Frequently Asked Questions
What does test__format_messages_with_cache_control() do?
test__format_messages_with_cache_control() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py.
Where is test__format_messages_with_cache_control() defined?
test__format_messages_with_cache_control() is defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py at line 855.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free