Class ImageContent

java.lang.Object
dev.langchain4j.data.message.ImageContent
All Implemented Interfaces:
Content

public class ImageContent extends Object implements Content
Represents an image with a DetailLevel.
  • Constructor Details

    • ImageContent

      public ImageContent(URI url)
      Create a new ImageContent from the given url.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      url - the url of the image.
    • ImageContent

      public ImageContent(String url)
      Create a new ImageContent from the given url.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      url - the url of the image.
    • ImageContent

      public ImageContent(URI url, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given url and detail level.
      Parameters:
      url - the url of the image.
      detailLevel - the detail level of the image.
    • ImageContent

      public ImageContent(String url, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given url and detail level.
      Parameters:
      url - the url of the image.
      detailLevel - the detail level of the image.
    • ImageContent

      public ImageContent(String base64Data, String mimeType)
      Create a new ImageContent from the given base64 data and mime type.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      base64Data - the base64 data of the image.
      mimeType - the mime type of the image.
    • ImageContent

      public ImageContent(String base64Data, String mimeType, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given base64 data and mime type.
      Parameters:
      base64Data - the base64 data of the image.
      mimeType - the mime type of the image.
      detailLevel - the detail level of the image.
    • ImageContent

      public ImageContent(Image image)
      Create a new ImageContent from the given image.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      image - the image.
    • ImageContent

      public ImageContent(Image image, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given image.
      Parameters:
      image - the image.
      detailLevel - the detail level of the image.
  • Method Details

    • image

      public Image image()
      Get the Image.
      Returns:
      the Image.
    • detailLevel

      public ImageContent.DetailLevel detailLevel()
      Get the DetailLevel.
      Returns:
      the DetailLevel.
    • detailLevelSpecified

      @Experimental public boolean detailLevelSpecified()
      Returns whether the detail level was given when this image content was created. When it was not given, detailLevel() returns ImageContent.DetailLevel.LOW. Code that sends the image elsewhere can use this to choose its own detail level only when the creator did not choose one.

      An image content read from JSON (for example from a stored chat memory) counts as having its detail level given, because the JSON contains the detail level.

      This value is not part of equals(Object), hashCode() or toString(), and it is not written to JSON.

      Returns:
      true if a detail level was given when this image content was created
      Since:
      1.23.0
    • type

      public ContentType type()
      Description copied from interface: Content
      Returns the type of content.

      Can be used to cast the content to the correct type.

      Specified by:
      type in interface Content
      Returns:
      The type of content.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • from

      public static ImageContent from(URI url)
      Create a new ImageContent from the given url.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      url - the url of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(String url)
      Create a new ImageContent from the given url.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      url - the url of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(URI url, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given url and detail level.
      Parameters:
      url - the url of the image.
      detailLevel - the detail level of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(String url, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given url and detail level.
      Parameters:
      url - the url of the image.
      detailLevel - the detail level of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(String base64Data, String mimeType)
      Create a new ImageContent from the given base64 data and mime type.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      base64Data - the base64 data of the image.
      mimeType - the mime type of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(String base64Data, String mimeType, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given base64 data and mime type.
      Parameters:
      base64Data - the base64 data of the image.
      mimeType - the mime type of the image.
      detailLevel - the detail level of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(Path imageFilePath, String mimeType)
      Create a new ImageContent from the file at the given path and mime type.
      Parameters:
      imageFilePath - the path to the image file.
      mimeType - the mime type of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(Path imageFilePath, String mimeType, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the file at the given path and mime type.
      Parameters:
      imageFilePath - the path to the image file.
      mimeType - the mime type of the image.
      detailLevel - the detail level of the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(Image image)
      Create a new ImageContent from the given image.

      The image will be created with DetailLevel.LOW detail.

      Parameters:
      image - the image.
      Returns:
      the new ImageContent.
    • from

      public static ImageContent from(Image image, ImageContent.DetailLevel detailLevel)
      Create a new ImageContent from the given image.
      Parameters:
      image - the image.
      detailLevel - the detail level of the image.
      Returns:
      the new ImageContent.