test_convert_to_openai_messages_anthropic() — langchain Function Reference
Architecture documentation for the test_convert_to_openai_messages_anthropic() function in test_utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 2e9528f1_b8ee_7620_e40f_bc01b0549549["test_convert_to_openai_messages_anthropic()"] ea3f8d89_f44b_6738_3cb9_a740a73cfca4["test_utils.py"] 2e9528f1_b8ee_7620_e40f_bc01b0549549 -->|defined in| ea3f8d89_f44b_6738_3cb9_a740a73cfca4 14e6fdde_cf6a_539a_67f6_36fd8fde5d20["create_image_data()"] 2e9528f1_b8ee_7620_e40f_bc01b0549549 -->|calls| 14e6fdde_cf6a_539a_67f6_36fd8fde5d20 1dd19a53_952f_5baf_39c4_aa23f0cd7f59["create_base64_image()"] 2e9528f1_b8ee_7620_e40f_bc01b0549549 -->|calls| 1dd19a53_952f_5baf_39c4_aa23f0cd7f59 style 2e9528f1_b8ee_7620_e40f_bc01b0549549 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/messages/test_utils.py lines 1068–1156
def test_convert_to_openai_messages_anthropic() -> None:
image_data = create_image_data()
messages = [
HumanMessage(
content=[
{
"type": "text",
"text": "Here's an image:",
"cache_control": {"type": "ephemeral"},
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": image_data,
},
},
]
),
AIMessage(
content=[
{"type": "tool_use", "name": "foo", "input": {"bar": "baz"}, "id": "1"}
]
),
HumanMessage(
content=[
{
"type": "tool_result",
"tool_use_id": "1",
"is_error": False,
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": image_data,
},
},
],
}
]
),
]
result = convert_to_openai_messages(messages)
expected = [
{
"role": "user",
"content": [
{"type": "text", "text": "Here's an image:"},
{"type": "image_url", "image_url": {"url": create_base64_image()}},
],
},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"type": "function",
"function": {
"name": "foo",
"arguments": json.dumps({"bar": "baz"}),
},
"id": "1",
}
],
},
{
"role": "tool",
"content": [
{"type": "image_url", "image_url": {"url": create_base64_image()}}
],
"tool_call_id": "1",
},
]
assert result == expected
# Test thinking blocks (pass through)
thinking_block = {
"signature": "abc123",
Domain
Subdomains
Source
Frequently Asked Questions
What does test_convert_to_openai_messages_anthropic() do?
test_convert_to_openai_messages_anthropic() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_convert_to_openai_messages_anthropic() defined?
test_convert_to_openai_messages_anthropic() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 1068.
What does test_convert_to_openai_messages_anthropic() call?
test_convert_to_openai_messages_anthropic() calls 2 function(s): create_base64_image, create_image_data.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free