_chunk_to_msg() — langchain Function Reference
Architecture documentation for the _chunk_to_msg() function in utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 42b7cd62_fb9b_666d_1162_ef1187915080["_chunk_to_msg()"] 0b528c80_0ce7_1c74_8932_bc433bcb03c6["utils.py"] 42b7cd62_fb9b_666d_1162_ef1187915080 -->|defined in| 0b528c80_0ce7_1c74_8932_bc433bcb03c6 23370d26_f8d8_9847_9d6f_8efb2a70861b["merge_message_runs()"] 23370d26_f8d8_9847_9d6f_8efb2a70861b -->|calls| 42b7cd62_fb9b_666d_1162_ef1187915080 style 42b7cd62_fb9b_666d_1162_ef1187915080 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/utils.py lines 2110–2128
def _chunk_to_msg(chunk: BaseMessageChunk) -> BaseMessage:
if chunk.__class__ in _CHUNK_MSG_MAP:
return _CHUNK_MSG_MAP[chunk.__class__](
**chunk.model_dump(exclude={"type", "tool_call_chunks", "chunk_position"})
)
for chunk_cls, msg_cls in _CHUNK_MSG_MAP.items():
if isinstance(chunk, chunk_cls):
return msg_cls(
**chunk.model_dump(
exclude={"type", "tool_call_chunks", "chunk_position"}
)
)
msg = (
f"Unrecognized message chunk class {chunk.__class__}. Supported classes are "
f"{list(_CHUNK_MSG_MAP.keys())}"
)
msg = create_message(message=msg, error_code=ErrorCode.MESSAGE_COERCION_FAILURE)
raise ValueError(msg)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does _chunk_to_msg() do?
_chunk_to_msg() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/utils.py.
Where is _chunk_to_msg() defined?
_chunk_to_msg() is defined in libs/core/langchain_core/messages/utils.py at line 2110.
What calls _chunk_to_msg()?
_chunk_to_msg() is called by 1 function(s): merge_message_runs.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free