Home / Function/ _convert_to_v1_from_chat_completions() — langchain Function Reference

_convert_to_v1_from_chat_completions() — langchain Function Reference

Architecture documentation for the _convert_to_v1_from_chat_completions() function in openai.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ff798f74_5068_bddf_4e8d_fd7028b514da["_convert_to_v1_from_chat_completions()"]
  3f58992c_878c_57d1_7412_5e64743aa7ba["openai.py"]
  ff798f74_5068_bddf_4e8d_fd7028b514da -->|defined in| 3f58992c_878c_57d1_7412_5e64743aa7ba
  af54f3fb_5bfb_6940_293f_4c3b25c7f24f["translate_content()"]
  af54f3fb_5bfb_6940_293f_4c3b25c7f24f -->|calls| ff798f74_5068_bddf_4e8d_fd7028b514da
  style ff798f74_5068_bddf_4e8d_fd7028b514da fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/block_translators/openai.py lines 154–175

def _convert_to_v1_from_chat_completions(
    message: AIMessage,
) -> list[types.ContentBlock]:
    """Mutate a Chat Completions message to v1 format."""
    content_blocks: list[types.ContentBlock] = []
    if isinstance(message.content, str):
        if message.content:
            content_blocks = [{"type": "text", "text": message.content}]
        else:
            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

Frequently Asked Questions

What does _convert_to_v1_from_chat_completions() do?
_convert_to_v1_from_chat_completions() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/block_translators/openai.py.
Where is _convert_to_v1_from_chat_completions() defined?
_convert_to_v1_from_chat_completions() is defined in libs/core/langchain_core/messages/block_translators/openai.py at line 154.
What calls _convert_to_v1_from_chat_completions()?
_convert_to_v1_from_chat_completions() is called by 1 function(s): translate_content.

Analyze Your Own Codebase

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

Try Supermodel Free