_compat.py — langchain Source File
Architecture documentation for _compat.py, a python file in the langchain codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 6254a638_0b68_52c5_4b1c_c3e7e5f6aad2["_compat.py"] d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 6254a638_0b68_52c5_4b1c_c3e7e5f6aad2 --> d758344f_537f_649e_f467_b9d7442e86df 23170be8_e8a8_a728_6471_2a7fe6195245["langchain_core.messages.block_translators"] 6254a638_0b68_52c5_4b1c_c3e7e5f6aad2 --> 23170be8_e8a8_a728_6471_2a7fe6195245 style 6254a638_0b68_52c5_4b1c_c3e7e5f6aad2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Derivations of standard content blocks from mistral content."""
from __future__ import annotations
from langchain_core.messages import AIMessage, AIMessageChunk
from langchain_core.messages import content as types
from langchain_core.messages.block_translators import register_translator
def _convert_from_v1_to_mistral(
content: list[types.ContentBlock],
model_provider: str | None,
) -> str | list[str | dict]:
new_content: list = []
for block in content:
if block["type"] == "text":
new_content.append({"text": block.get("text", ""), "type": "text"})
elif (
block["type"] == "reasoning"
and (reasoning := block.get("reasoning"))
and isinstance(reasoning, str)
and model_provider == "mistralai"
):
new_content.append(
{
"type": "thinking",
"thinking": [{"type": "text", "text": reasoning}],
}
)
elif (
block["type"] == "non_standard"
and "value" in block
and model_provider == "mistralai"
):
new_content.append(block["value"])
elif block["type"] == "tool_call":
continue
else:
new_content.append(block)
return new_content
def _convert_to_v1_from_mistral(message: AIMessage) -> list[types.ContentBlock]:
"""Convert mistral message content to v1 format."""
if isinstance(message.content, str):
content_blocks: list[types.ContentBlock] = [
{"type": "text", "text": message.content}
]
else:
content_blocks = []
for block in message.content:
if isinstance(block, str):
content_blocks.append({"type": "text", "text": block})
elif isinstance(block, dict):
if block.get("type") == "text" and isinstance(block.get("text"), str):
// ... (66 more lines)
Domain
Subdomains
Functions
Dependencies
- langchain_core.messages
- langchain_core.messages.block_translators
Source
Frequently Asked Questions
What does _compat.py do?
_compat.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in _compat.py?
_compat.py defines 4 function(s): _convert_from_v1_to_mistral, _convert_to_v1_from_mistral, translate_content, translate_content_chunk.
What does _compat.py depend on?
_compat.py imports 2 module(s): langchain_core.messages, langchain_core.messages.block_translators.
Where is _compat.py in the architecture?
_compat.py is located at libs/partners/mistralai/langchain_mistralai/_compat.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/partners/mistralai/langchain_mistralai).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free