Home / File/ _compat.py — langchain Source File

_compat.py — langchain Source File

Architecture documentation for _compat.py, a python file in the langchain codebase. 1 imports, 0 dependents.

File python CoreAbstractions MessageSchema 1 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  4c7a2bbb_9378_0b2b_2d1c_2dee744cbff2["_compat.py"]
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  4c7a2bbb_9378_0b2b_2d1c_2dee744cbff2 --> d758344f_537f_649e_f467_b9d7442e86df
  style 4c7a2bbb_9378_0b2b_2d1c_2dee744cbff2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Converts between AIMessage output formats, governed by `output_version`."""

from __future__ import annotations

from langchain_core.messages import AIMessage


def _convert_from_v1_to_chat_completions(message: AIMessage) -> AIMessage:
    """Convert a v1 message to the Chat Completions format."""
    if isinstance(message.content, list):
        new_content: list = []
        for block in message.content:
            if isinstance(block, dict):
                block_type = block.get("type")
                if block_type == "text":
                    # Strip annotations
                    new_content.append({"type": "text", "text": block["text"]})
                elif block_type in ("reasoning", "tool_call"):
                    pass
                else:
                    new_content.append(block)
            else:
                new_content.append(block)
        return message.model_copy(update={"content": new_content})

    return message

Subdomains

Dependencies

  • langchain_core.messages

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, MessageSchema subdomain.
What functions are defined in _compat.py?
_compat.py defines 1 function(s): _convert_from_v1_to_chat_completions.
What does _compat.py depend on?
_compat.py imports 1 module(s): langchain_core.messages.
Where is _compat.py in the architecture?
_compat.py is located at libs/partners/fireworks/langchain_fireworks/_compat.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/partners/fireworks/langchain_fireworks).

Analyze Your Own Codebase

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

Try Supermodel Free