ReqLLM.Message.ContentPart (ReqLLM v1.19.0)

View Source

ContentPart represents a single piece of content within a message.

Supports multiple content types:

  • :text - Plain text content
  • :image_url - Image from URL
  • :video_url - Video from URL
  • :image - Image from binary data
  • :file - File attachment or uploaded file reference
  • :thinking - Chain-of-thought thinking content

Provider-owned file references are opt-in through owned_file_id/3. Legacy file_id/1 values remain unowned and preserve their existing behavior.

See also

  • ReqLLM.Message - Multi-modal message composition using ContentPart collections

Summary

Types

t()

@type t() :: %ReqLLM.Message.ContentPart{
  data: nil | nil | any(),
  file_id: nil | nil | binary(),
  filename: nil | nil | binary(),
  media_type: nil | nil | binary(),
  metadata: map(),
  text: nil | nil | binary(),
  type: :text | :image_url | :video_url | :image | :file | :thinking,
  url: nil | nil | binary()
}

Functions

file(data, filename, media_type \\ "application/octet-stream")

@spec file(binary(), String.t(), String.t()) :: t()

file_id(file_id, media_type_or_metadata \\ "application/pdf", metadata \\ %{})

@spec file_id(String.t(), String.t(), map()) :: t()

image(data, media_type \\ "image/png")

@spec image(binary(), String.t()) :: t()

image(data, media_type, metadata)

@spec image(binary(), String.t(), map()) :: t()

image_url(url)

@spec image_url(String.t()) :: t()

image_url(url, metadata)

@spec image_url(String.t(), map()) :: t()

inspect_provider_file(part)

@spec inspect_provider_file(t() | map()) ::
  {:ok, ReqLLM.ProviderFileReference.t()} | :error

Returns redacted provider file metadata suitable for logs and diagnostics.

owned_file?(part)

@spec owned_file?(t() | map()) :: boolean()

Returns whether a file reference has explicit provider ownership metadata.

owned_file_id(file_id, provider, opts \\ [])

@spec owned_file_id(String.t(), atom() | String.t(), keyword()) :: t()

Creates an explicitly provider-owned file reference.

Ownership is stored in the reserved "req_llm" -> "provider_file" metadata namespace. Legacy file_id/1 references remain unowned and keep their existing behavior.

Supported options are :media_type, :metadata, :purpose, :status, :expires_at, :size, :sha256, and :provider_metadata.

provider_file_reference(part)

@spec provider_file_reference(t() | map()) ::
  {:ok, ReqLLM.ProviderFileReference.t()} | :error

Returns the full metadata record for an explicitly owned provider file.

schema()

Returns the Zoi schema for this module

text(content)

@spec text(String.t()) :: t()

text(content, metadata)

@spec text(String.t(), map()) :: t()

thinking(content)

@spec thinking(String.t()) :: t()

thinking(content, metadata)

@spec thinking(String.t(), map()) :: t()

valid?(arg1)

@spec valid?(t()) :: boolean()

video_url(url)

@spec video_url(String.t()) :: t()

video_url(url, metadata)

@spec video_url(String.t(), map()) :: t()