test_cache_control_kwarg() — langchain Function Reference
Architecture documentation for the test_cache_control_kwarg() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 995c24a4_58a4_ec2c_4606_66573198e24b["test_cache_control_kwarg()"] 18428dc5_a41b_90c6_88ad_615296ee3311["test_chat_models.py"] 995c24a4_58a4_ec2c_4606_66573198e24b -->|defined in| 18428dc5_a41b_90c6_88ad_615296ee3311 style 995c24a4_58a4_ec2c_4606_66573198e24b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/tests/unit_tests/test_chat_models.py lines 1487–1533
def test_cache_control_kwarg() -> None:
llm = ChatAnthropic(model=MODEL_NAME)
messages = [HumanMessage("foo"), AIMessage("bar"), HumanMessage("baz")]
payload = llm._get_request_payload(messages)
assert payload["messages"] == [
{"role": "user", "content": "foo"},
{"role": "assistant", "content": "bar"},
{"role": "user", "content": "baz"},
]
payload = llm._get_request_payload(messages, cache_control={"type": "ephemeral"})
assert payload["messages"] == [
{"role": "user", "content": "foo"},
{"role": "assistant", "content": "bar"},
{
"role": "user",
"content": [
{"type": "text", "text": "baz", "cache_control": {"type": "ephemeral"}}
],
},
]
assert isinstance(messages[-1].content, str) # test no mutation
messages = [
HumanMessage("foo"),
AIMessage("bar"),
HumanMessage(
content=[
{"type": "text", "text": "baz"},
{"type": "text", "text": "qux"},
]
),
]
payload = llm._get_request_payload(messages, cache_control={"type": "ephemeral"})
assert payload["messages"] == [
{"role": "user", "content": "foo"},
{"role": "assistant", "content": "bar"},
{
"role": "user",
"content": [
{"type": "text", "text": "baz"},
{"type": "text", "text": "qux", "cache_control": {"type": "ephemeral"}},
],
},
]
assert "cache_control" not in messages[-1].content[-1] # test no mutation
Domain
Subdomains
Source
Frequently Asked Questions
What does test_cache_control_kwarg() do?
test_cache_control_kwarg() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py.
Where is test_cache_control_kwarg() defined?
test_cache_control_kwarg() is defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py at line 1487.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free