LangchainPrompt.Attachment (LangchainPrompt v0.1.0)

Copy Markdown View Source

A file attachment to be sent alongside a prompt to the LLM.

Attachments are adapter-agnostic containers for binary data (images, PDFs, etc.) that get merged into the user message by LangchainPrompt.execute/4.

Creating attachments

# From raw base64 data
%Attachment{type: :image, content: base64_data, media: :jpg}

# From a file on disk (reads, base64-encodes, infers media type)
Attachment.from_file!("/path/to/menu.jpg")

Supported extensions

Extension:type:media
.jpg / .jpeg:image:jpg
.png:image:png
.gif:image:gif
.webp:image:webp
.pdf:file:pdf

Summary

Functions

Creates an Attachment from a file path.

Types

t()

@type t() :: %LangchainPrompt.Attachment{
  content: binary(),
  media: atom() | String.t(),
  type: :image | :file
}

Functions

from_file!(path)

@spec from_file!(path :: String.t()) :: t() | no_return()

Creates an Attachment from a file path.

Reads the file, base64-encodes the content, and infers the :type and :media from the file extension.

Raises ArgumentError on unsupported extensions and re-raises any File.Error from reading the file.