test_ai.py — langchain Source File
Architecture documentation for test_ai.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 019a0d96_5683_eb54_aa7b_9735510bdb19["test_ai.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 019a0d96_5683_eb54_aa7b_9735510bdb19 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 36cce5da_d805_04c3_7e86_e1b4dd49b497["langchain_core.load"] 019a0d96_5683_eb54_aa7b_9735510bdb19 --> 36cce5da_d805_04c3_7e86_e1b4dd49b497 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 019a0d96_5683_eb54_aa7b_9735510bdb19 --> d758344f_537f_649e_f467_b9d7442e86df 4eb42b7a_5c64_04cb_fcec_1401d5c10628["langchain_core.messages.ai"] 019a0d96_5683_eb54_aa7b_9735510bdb19 --> 4eb42b7a_5c64_04cb_fcec_1401d5c10628 552bc7bf_c1ac_965d_e157_ee750ab1993c["langchain_core.messages.tool"] 019a0d96_5683_eb54_aa7b_9735510bdb19 --> 552bc7bf_c1ac_965d_e157_ee750ab1993c style 019a0d96_5683_eb54_aa7b_9735510bdb19 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import cast
from langchain_core.load import dumpd, load
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
from langchain_core.messages.ai import (
InputTokenDetails,
OutputTokenDetails,
UsageMetadata,
add_ai_message_chunks,
add_usage,
subtract_usage,
)
from langchain_core.messages.tool import invalid_tool_call as create_invalid_tool_call
from langchain_core.messages.tool import tool_call as create_tool_call
from langchain_core.messages.tool import tool_call_chunk as create_tool_call_chunk
def test_serdes_message() -> None:
msg = AIMessage(
content=[{"text": "blah", "type": "text"}],
tool_calls=[create_tool_call(name="foo", args={"bar": 1}, id="baz")],
invalid_tool_calls=[
create_invalid_tool_call(name="foobad", args="blah", id="booz", error="bad")
],
)
expected = {
"lc": 1,
"type": "constructor",
"id": ["langchain", "schema", "messages", "AIMessage"],
"kwargs": {
"type": "ai",
"content": [{"text": "blah", "type": "text"}],
"tool_calls": [
{"name": "foo", "args": {"bar": 1}, "id": "baz", "type": "tool_call"}
],
"invalid_tool_calls": [
{
"name": "foobad",
"args": "blah",
"id": "booz",
"error": "bad",
"type": "invalid_tool_call",
}
],
},
}
actual = dumpd(msg)
assert actual == expected
assert load(actual, allowed_objects=[AIMessage]) == msg
def test_serdes_message_chunk() -> None:
chunk = AIMessageChunk(
content=[{"text": "blah", "type": "text"}],
tool_call_chunks=[
create_tool_call_chunk(name="foo", args='{"bar": 1}', id="baz", index=0),
create_tool_call_chunk(
name="foobad",
args="blah",
// ... (445 more lines)
Domain
Subdomains
Functions
- test_add_ai_message_chunks_usage()
- test_add_usage_both_none()
- test_add_usage_both_present()
- test_add_usage_one_none()
- test_add_usage_with_details()
- test_content_blocks()
- test_content_blocks_reasoning_extraction()
- test_init_tool_calls()
- test_serdes_message()
- test_serdes_message_chunk()
- test_subtract_usage_both_none()
- test_subtract_usage_both_present()
- test_subtract_usage_one_none()
- test_subtract_usage_with_negative_result()
Dependencies
- langchain_core.load
- langchain_core.messages
- langchain_core.messages.ai
- langchain_core.messages.tool
- typing
Source
Frequently Asked Questions
What does test_ai.py do?
test_ai.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_ai.py?
test_ai.py defines 14 function(s): test_add_ai_message_chunks_usage, test_add_usage_both_none, test_add_usage_both_present, test_add_usage_one_none, test_add_usage_with_details, test_content_blocks, test_content_blocks_reasoning_extraction, test_init_tool_calls, test_serdes_message, test_serdes_message_chunk, and 4 more.
What does test_ai.py depend on?
test_ai.py imports 5 module(s): langchain_core.load, langchain_core.messages, langchain_core.messages.ai, langchain_core.messages.tool, typing.
Where is test_ai.py in the architecture?
test_ai.py is located at libs/core/tests/unit_tests/messages/test_ai.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/core/tests/unit_tests/messages).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free