Home / Function/ create_image_block() — langchain Function Reference

create_image_block() — langchain Function Reference

Architecture documentation for the create_image_block() function in content.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  409ec246_835b_40ad_7088_50f867d0b17d["create_image_block()"]
  c7f11daf_e104_efbe_7225_f1d6da8e8630["content.py"]
  409ec246_835b_40ad_7088_50f867d0b17d -->|defined in| c7f11daf_e104_efbe_7225_f1d6da8e8630
  style 409ec246_835b_40ad_7088_50f867d0b17d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/content.py lines 995–1054

def create_image_block(
    *,
    url: str | None = None,
    base64: str | None = None,
    file_id: str | None = None,
    mime_type: str | None = None,
    id: str | None = None,
    index: int | str | None = None,
    **kwargs: Any,
) -> ImageContentBlock:
    """Create an `ImageContentBlock`.

    Args:
        url: URL of the image.
        base64: Base64-encoded image data.
        file_id: ID of the image file from a file storage system.
        mime_type: MIME type of the image.

            Required for base64 data.
        id: Content block identifier.

            Generated automatically if not provided.
        index: Index of block in aggregate response.

            Used during streaming.

    Returns:
        A properly formatted `ImageContentBlock`.

    Raises:
        ValueError: If no image source is provided or if `base64` is used without
            `mime_type`.

    !!! note

        The `id` is generated automatically if not provided, using a UUID4 format
        prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
    """
    if not any([url, base64, file_id]):
        msg = "Must provide one of: url, base64, or file_id"
        raise ValueError(msg)

    block = ImageContentBlock(type="image", id=ensure_id(id))

    if url is not None:
        block["url"] = url
    if base64 is not None:
        block["base64"] = base64
    if file_id is not None:
        block["file_id"] = file_id
    if mime_type is not None:
        block["mime_type"] = mime_type
    if index is not None:
        block["index"] = index

    extras = {k: v for k, v in kwargs.items() if v is not None}
    if extras:
        block["extras"] = extras

    return block

Domain

Subdomains

Frequently Asked Questions

What does create_image_block() do?
create_image_block() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/content.py.
Where is create_image_block() defined?
create_image_block() is defined in libs/core/langchain_core/messages/content.py at line 995.

Analyze Your Own Codebase

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

Try Supermodel Free