_convert_to_v1_from_mistral() — langchain Function Reference
Architecture documentation for the _convert_to_v1_from_mistral() function in _compat.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 881573b2_0ea0_ce4d_8772_0bb4efe4427b["_convert_to_v1_from_mistral()"] 93f8f3a4_a00a_3cbb_6048_6799a3ca5301["_compat.py"] 881573b2_0ea0_ce4d_8772_0bb4efe4427b -->|defined in| 93f8f3a4_a00a_3cbb_6048_6799a3ca5301 500ada99_83e8_6642_8552_4dc4dcd3d38a["translate_content()"] 500ada99_83e8_6642_8552_4dc4dcd3d38a -->|calls| 881573b2_0ea0_ce4d_8772_0bb4efe4427b b952c82f_9391_6fd0_850d_29a35d34c7a0["translate_content_chunk()"] b952c82f_9391_6fd0_850d_29a35d34c7a0 -->|calls| 881573b2_0ea0_ce4d_8772_0bb4efe4427b style 881573b2_0ea0_ce4d_8772_0bb4efe4427b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/mistralai/langchain_mistralai/_compat.py lines 46–112
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):
text_block: types.TextContentBlock = {
"type": "text",
"text": block["text"],
}
if "index" in block:
text_block["index"] = block["index"]
content_blocks.append(text_block)
elif block.get("type") == "thinking" and isinstance(
block.get("thinking"), list
):
for sub_block in block["thinking"]:
if (
isinstance(sub_block, dict)
and sub_block.get("type") == "text"
):
reasoning_block: types.ReasoningContentBlock = {
"type": "reasoning",
"reasoning": sub_block.get("text", ""),
}
if "index" in block:
reasoning_block["index"] = block["index"]
content_blocks.append(reasoning_block)
else:
non_standard_block: types.NonStandardContentBlock = {
"type": "non_standard",
"value": block,
}
content_blocks.append(non_standard_block)
else:
continue
if (
len(content_blocks) == 1
and content_blocks[0].get("type") == "text"
and content_blocks[0].get("text") == ""
and message.tool_calls
):
content_blocks = []
for tool_call in message.tool_calls:
content_blocks.append(
{
"type": "tool_call",
"name": tool_call["name"],
"args": tool_call["args"],
"id": tool_call.get("id"),
}
)
return content_blocks
Domain
Subdomains
Source
Frequently Asked Questions
What does _convert_to_v1_from_mistral() do?
_convert_to_v1_from_mistral() is a function in the langchain codebase, defined in libs/partners/mistralai/langchain_mistralai/_compat.py.
Where is _convert_to_v1_from_mistral() defined?
_convert_to_v1_from_mistral() is defined in libs/partners/mistralai/langchain_mistralai/_compat.py at line 46.
What calls _convert_to_v1_from_mistral()?
_convert_to_v1_from_mistral() is called by 2 function(s): translate_content, translate_content_chunk.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free