Jidoka.ContentPart (Jidoka v0.9.0)

Copy Markdown View Source

Provider-neutral text and media content for requests, messages, and results.

Media parts use one source: {:url, url}, {:data, binary}, or {:file_id, id}. The durable struct keeps the source value. Public projections omit the value and show only its kind and safe size data.

Summary

Functions

Builds an audio part.

Builds a document part.

Normalizes a content part struct, keyword list, or map.

Normalizes an ordered content-part list.

Builds an image part.

Builds a content part from a keyword list or map.

Builds a content part and raises if it is not valid.

Returns the Zoi schema for a content part.

Returns the source kind for a media part.

Returns a non-empty text summary for controls, memory, and debugging.

Builds a text part.

Returns the text in an ordered part list.

Converts a part into a complete map for an adapter.

Returns the supported content types.

Builds a video part.

Types

content_type()

@type content_type() :: :text | :image | :audio | :video | :document

input()

@type input() :: t() | keyword() | map()

source()

@type source() :: {:url, String.t()} | {:data, binary()} | {:file_id, String.t()}

t()

@type t() :: %Jidoka.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) | :audio) | :video) | :document,
  url: nil | nil | binary()
}

Functions

audio(source, opts \\ [])

@spec audio(
  source(),
  keyword()
) :: t()

Builds an audio part.

document(source, opts \\ [])

@spec document(
  source(),
  keyword()
) :: t()

Builds a document part.

from_input(part)

@spec from_input(input()) :: {:ok, t()} | {:error, term()}

Normalizes a content part struct, keyword list, or map.

from_inputs(inputs)

@spec from_inputs([input()]) :: {:ok, [t()]} | {:error, term()}

Normalizes an ordered content-part list.

image(source, opts \\ [])

@spec image(
  source(),
  keyword()
) :: t()

Builds an image part.

new(attrs)

@spec new(keyword() | map()) :: {:ok, t()} | {:error, term()}

Builds a content part from a keyword list or map.

new!(attrs)

@spec new!(keyword() | map()) :: t()

Builds a content part and raises if it is not valid.

schema()

@spec schema() :: Zoi.schema()

Returns the Zoi schema for a content part.

source_kind(content_part)

@spec source_kind(t()) :: :text | :url | :data | :file_id

Returns the source kind for a media part.

summary(parts)

@spec summary([t()]) :: String.t()

Returns a non-empty text summary for controls, memory, and debugging.

text(text, opts \\ [])

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

Builds a text part.

text_content(parts)

@spec text_content([t()]) :: String.t()

Returns the text in an ordered part list.

to_map(part)

@spec to_map(t()) :: map()

Converts a part into a complete map for an adapter.

types()

@spec types() :: [content_type()]

Returns the supported content types.

video(source, opts \\ [])

@spec video(
  source(),
  keyword()
) :: t()

Builds a video part.