View Source LangChain.Message.ContentPart (LangChain v0.2.0)
Models a ContentPart
. Some LLMs support combining text, images, and possibly
other content as part of a single user message. A ContentPart
represents a
block, or part, of a message's content that is all of one type.
Types
:text
- The message part is text.:image_url
- The message part is a URL to an image.:image
- The message part is image data that is base64 encoded text.
Fields
:content
- Text content.:options
- Options that may be specific to the LLM for a particular message type. For example, Anthropic requires an image'smedia_type
to be provided by the caller. This can be provided usingmedia: "image/png"
.
Summary
Functions
Create a new ContentPart that contains an image encoded as base64 data. Raises an exception if not valid.
Create a new ContentPart that contains a URL to an image. Raises an exception if not valid.
Build a new message and return an :ok
/:error
tuple with the result.
Build a new message and return it or raise an error if invalid.
Create a new ContentPart that contains text. Raises an exception if not valid.
Types
Functions
Create a new ContentPart that contains an image encoded as base64 data. Raises an exception if not valid.
Options
:media
- Provide the "media type" for the image. Examples: "image/jpeg", "image/png", etc. ChatGPT does not require this but other LLMs may.
Create a new ContentPart that contains a URL to an image. Raises an exception if not valid.
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Build a new message and return an :ok
/:error
tuple with the result.
Build a new message and return it or raise an error if invalid.
Example
ContentPart.new!(%{type: :text, content: "Greetings!"})
ContentPart.new!(%{type: :image_url, content: "https://example.com/images/house.jpg"})
Create a new ContentPart that contains text. Raises an exception if not valid.