Jido.AI.Prompt.MessageItem (Jido AI v0.5.2)
View SourceRepresents 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
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
Functions
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"}
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}
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"}
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}
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}
Creates a new text content part.
Examples
iex> Jido.AI.Prompt.MessageItem.text_part("Hello")
%{type: :text, text: "Hello"}