Home / Function/ convert_to_openai_image_block() — langchain Function Reference

convert_to_openai_image_block() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  b393fabd_bb2e_e495_7eb7_a1b28f086abb["convert_to_openai_image_block()"]
  3f58992c_878c_57d1_7412_5e64743aa7ba["openai.py"]
  b393fabd_bb2e_e495_7eb7_a1b28f086abb -->|defined in| 3f58992c_878c_57d1_7412_5e64743aa7ba
  4baa66e7_67cf_c45d_8bd4_a50f1900fbf8["convert_to_openai_data_block()"]
  4baa66e7_67cf_c45d_8bd4_a50f1900fbf8 -->|calls| b393fabd_bb2e_e495_7eb7_a1b28f086abb
  style b393fabd_bb2e_e495_7eb7_a1b28f086abb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/block_translators/openai.py lines 22–55

def convert_to_openai_image_block(block: dict[str, Any]) -> dict:
    """Convert `ImageContentBlock` to format expected by OpenAI Chat Completions.

    Args:
        block: The image content block to convert.

    Raises:
        ValueError: If required keys are missing.
        ValueError: If source type is unsupported.

    Returns:
        The formatted image content block.
    """
    if "url" in block:
        return {
            "type": "image_url",
            "image_url": {
                "url": block["url"],
            },
        }
    if "base64" in block or block.get("source_type") == "base64":
        if "mime_type" not in block:
            error_message = "mime_type key is required for base64 data."
            raise ValueError(error_message)
        mime_type = block["mime_type"]
        base64_data = block["data"] if "data" in block else block["base64"]
        return {
            "type": "image_url",
            "image_url": {
                "url": f"data:{mime_type};base64,{base64_data}",
            },
        }
    error_message = "Unsupported source type. Only 'url' and 'base64' are supported."
    raise ValueError(error_message)

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free