Home / Function/ _convert_mistral_chat_message_to_message() — langchain Function Reference

_convert_mistral_chat_message_to_message() — langchain Function Reference

Architecture documentation for the _convert_mistral_chat_message_to_message() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4ae796f3_636f_9e57_c6e2_604b286b3ef4["_convert_mistral_chat_message_to_message()"]
  cfb937d2_ce7f_5338_2b62_6452043ac78a["chat_models.py"]
  4ae796f3_636f_9e57_c6e2_604b286b3ef4 -->|defined in| cfb937d2_ce7f_5338_2b62_6452043ac78a
  6cdbf47d_ba54_e03d_a2e2_0ea218fadd33["_create_chat_result()"]
  6cdbf47d_ba54_e03d_a2e2_0ea218fadd33 -->|calls| 4ae796f3_636f_9e57_c6e2_604b286b3ef4
  style 4ae796f3_636f_9e57_c6e2_604b286b3ef4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/mistralai/langchain_mistralai/chat_models.py lines 144–175

def _convert_mistral_chat_message_to_message(
    _message: dict,
) -> BaseMessage:
    role = _message["role"]
    if role != "assistant":
        msg = f"Expected role to be 'assistant', got {role}"
        raise ValueError(msg)
    # Mistral returns None for tool invocations
    content = _message.get("content", "") or ""

    additional_kwargs: dict = {}
    tool_calls = []
    invalid_tool_calls = []
    if raw_tool_calls := _message.get("tool_calls"):
        additional_kwargs["tool_calls"] = raw_tool_calls
        for raw_tool_call in raw_tool_calls:
            try:
                parsed: dict = cast(
                    "dict", parse_tool_call(raw_tool_call, return_id=True)
                )
                if not parsed["id"]:
                    parsed["id"] = uuid.uuid4().hex[:]
                tool_calls.append(parsed)
            except Exception as e:
                invalid_tool_calls.append(make_invalid_tool_call(raw_tool_call, str(e)))
    return AIMessage(
        content=content,
        additional_kwargs=additional_kwargs,
        tool_calls=tool_calls,
        invalid_tool_calls=invalid_tool_calls,
        response_metadata={"model_provider": "mistralai"},
    )

Domain

Subdomains

Frequently Asked Questions

What does _convert_mistral_chat_message_to_message() do?
_convert_mistral_chat_message_to_message() is a function in the langchain codebase, defined in libs/partners/mistralai/langchain_mistralai/chat_models.py.
Where is _convert_mistral_chat_message_to_message() defined?
_convert_mistral_chat_message_to_message() is defined in libs/partners/mistralai/langchain_mistralai/chat_models.py at line 144.
What calls _convert_mistral_chat_message_to_message()?
_convert_mistral_chat_message_to_message() is called by 1 function(s): _create_chat_result.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free