Jido.AI.Prompt.MessageItem (Jido AI v0.5.2)

View Source

Represents a single message item within a prompt.

Each message has a role (system, user, assistant, function) and content. The content can be either a raw string, an EEx template to be rendered, a Liquid template to be rendered, or a list of content parts for rich media support.

Summary

Types

t()

A message item within a prompt

Functions

Creates a new file content part.

Creates a new MessageItem struct from a map with string keys.

Creates a new image content part.

Creates a new MessageItem struct.

Creates a new MessageItem with multi-part content.

Creates a new text content part.

Types

t()

@type t() :: %Jido.AI.Prompt.MessageItem{
  content: String.t() | list(),
  engine: :eex | :liquid | :none,
  name: String.t(),
  role: atom()
}

A message item within a prompt

Functions

file_part(url)

Creates a new file content part.

Examples

iex> Jido.AI.Prompt.MessageItem.file_part("https://example.com/document.pdf")
%{type: :file_url, file_url: "https://example.com/document.pdf"}

from_map(map)

Creates a new MessageItem struct from a map with string keys.

This is useful when creating message items from JSON or other external sources.

Examples

iex> Jido.AI.Prompt.MessageItem.from_map(%{"role" => "user", "content" => "Hello"})
%Jido.AI.Prompt.MessageItem{role: :user, content: "Hello", engine: :none}

image_part(url)

Creates a new image content part.

Examples

iex> Jido.AI.Prompt.MessageItem.image_part("https://example.com/image.jpg")
%{type: :image_url, image_url: "https://example.com/image.jpg"}

new(attrs)

Creates a new MessageItem struct.

Examples

iex> Jido.AI.Prompt.MessageItem.new(%{role: :user, content: "Hello"})
%Jido.AI.Prompt.MessageItem{role: :user, content: "Hello", engine: :none}

iex> Jido.AI.Prompt.MessageItem.new(%{role: :system, content: "You are <%= @assistant_type %>", engine: :eex})
%Jido.AI.Prompt.MessageItem{role: :system, content: "You are <%= @assistant_type %>", engine: :eex}

iex> Jido.AI.Prompt.MessageItem.new(%{role: :user, content: "Hello {{ name }}", engine: :liquid})
%Jido.AI.Prompt.MessageItem{role: :user, content: "Hello {{ name }}", engine: :liquid}

new_multipart(role, parts)

Creates a new MessageItem with multi-part content.

Examples

iex> Jido.AI.Prompt.MessageItem.new_multipart(:user, [
...>   Jido.AI.Prompt.MessageItem.text_part("Check out this image:"),
...>   Jido.AI.Prompt.MessageItem.image_part("https://example.com/image.jpg")
...> ])
%Jido.AI.Prompt.MessageItem{role: :user, content: [
  %{type: :text, text: "Check out this image:"},
  %{type: :image_url, image_url: "https://example.com/image.jpg"}
], engine: :none}

text_part(text)

Creates a new text content part.

Examples

iex> Jido.AI.Prompt.MessageItem.text_part("Hello")
%{type: :text, text: "Hello"}