test_langchain_v0.py — langchain Source File
Architecture documentation for test_langchain_v0.py, a python file in the langchain codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 587266c7_f830_435d_d973_0d64235b5d35["test_langchain_v0.py"] d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 587266c7_f830_435d_d973_0d64235b5d35 --> d758344f_537f_649e_f467_b9d7442e86df 5d424099_b75b_144f_f438_6c504b51b923["langchain_core.messages.block_translators.langchain_v0"] 587266c7_f830_435d_d973_0d64235b5d35 --> 5d424099_b75b_144f_f438_6c504b51b923 6e27a55e_2e34_4dd3_6821_c8c2b0a67be6["tests.unit_tests.language_models.chat_models.test_base"] 587266c7_f830_435d_d973_0d64235b5d35 --> 6e27a55e_2e34_4dd3_6821_c8c2b0a67be6 style 587266c7_f830_435d_d973_0d64235b5d35 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from langchain_core.messages import HumanMessage
from langchain_core.messages import content as types
from langchain_core.messages.block_translators.langchain_v0 import (
_convert_legacy_v0_content_block_to_v1,
)
from tests.unit_tests.language_models.chat_models.test_base import (
_content_blocks_equal_ignore_id,
)
def test_convert_to_v1_from_openai_input() -> None:
message = HumanMessage(
content=[
{"type": "text", "text": "Hello"},
{
"type": "image",
"source_type": "url",
"url": "https://example.com/image.png",
},
{
"type": "image",
"source_type": "base64",
"data": "<base64 data>",
"mime_type": "image/png",
},
{
"type": "file",
"source_type": "url",
"url": "<document url>",
},
{
"type": "file",
"source_type": "base64",
"data": "<base64 data>",
"mime_type": "application/pdf",
},
{
"type": "audio",
"source_type": "base64",
"data": "<base64 data>",
"mime_type": "audio/mpeg",
},
{
"type": "file",
"source_type": "id",
"id": "<file id>",
},
]
)
expected: list[types.ContentBlock] = [
{"type": "text", "text": "Hello"},
{
"type": "image",
"url": "https://example.com/image.png",
},
{
"type": "image",
"base64": "<base64 data>",
"mime_type": "image/png",
},
{
"type": "file",
"url": "<document url>",
},
{
"type": "file",
"base64": "<base64 data>",
"mime_type": "application/pdf",
},
{
"type": "audio",
"base64": "<base64 data>",
"mime_type": "audio/mpeg",
},
{
"type": "file",
"file_id": "<file id>",
},
]
assert _content_blocks_equal_ignore_id(message.content_blocks, expected)
def test_convert_with_extras_on_v0_block() -> None:
"""Test that extras on old-style blocks are preserved in conversion.
Refer to `_extract_v0_extras` for details.
"""
block = {
"type": "image",
"source_type": "url",
"url": "https://example.com/image.png",
# extras follow
"alt_text": "An example image",
"caption": "Example caption",
"name": "example_image",
"description": None,
"attribution": None,
}
expected_output = {
"type": "image",
"url": "https://example.com/image.png",
"extras": {
"alt_text": "An example image",
"caption": "Example caption",
"name": "example_image",
# "description": None, # These are filtered out
# "attribution": None,
},
}
assert _convert_legacy_v0_content_block_to_v1(block) == expected_output
Domain
Subdomains
Dependencies
- langchain_core.messages
- langchain_core.messages.block_translators.langchain_v0
- tests.unit_tests.language_models.chat_models.test_base
Source
Frequently Asked Questions
What does test_langchain_v0.py do?
test_langchain_v0.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_langchain_v0.py?
test_langchain_v0.py defines 2 function(s): test_convert_to_v1_from_openai_input, test_convert_with_extras_on_v0_block.
What does test_langchain_v0.py depend on?
test_langchain_v0.py imports 3 module(s): langchain_core.messages, langchain_core.messages.block_translators.langchain_v0, tests.unit_tests.language_models.chat_models.test_base.
Where is test_langchain_v0.py in the architecture?
test_langchain_v0.py is located at libs/core/tests/unit_tests/messages/block_translators/test_langchain_v0.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/core/tests/unit_tests/messages/block_translators).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free