Class Media.Builder

java.lang.Object
org.springframework.ai.model.Media.Builder
Enclosing class:
Media

public static final class Media.Builder extends Object
Builder class for Media.
  • Method Details

    • mimeType

      public Media.Builder mimeType(org.springframework.util.MimeType mimeType)
      Sets the MIME type for the media object.
      Parameters:
      mimeType - the media MIME type, must not be null
      Returns:
      the builder instance
      Throws:
      IllegalArgumentException - if mimeType is null
    • data

      public Media.Builder data(org.springframework.core.io.Resource resource)
      Sets the media data from a Resource.
      Parameters:
      resource - the media resource, must not be null
      Returns:
      the builder instance
      Throws:
      IllegalArgumentException - if resource is null or if reading the resource content fails
    • data

      public Media.Builder data(Object data)
      Sets the media data from any Object.
      Parameters:
      data - the media data object, must not be null
      Returns:
      the builder instance
      Throws:
      IllegalArgumentException - if data is null
    • data

      public Media.Builder data(URL url)
      Sets the media data from a URL.
      Parameters:
      url - the media URL, must not be null
      Returns:
      the builder instance
      Throws:
      IllegalArgumentException - if url is null
    • id

      public Media.Builder id(String id)
      Sets the ID for the media object. The ID is typically assigned by AI models when they return a reference to previously provided media content.
      Parameters:
      id - the media identifier
      Returns:
      the builder instance
    • name

      public Media.Builder name(String name)
      Sets the name for the media object.

      Important security note: This field is vulnerable to prompt injections, as the model might inadvertently interpret it as instructions. It is recommended to specify neutral names.

      The name must only contain:

      • Alphanumeric characters
      • Whitespace characters (no more than one in a row)
      • Hyphens
      • Parentheses
      • Square brackets
      Parameters:
      name - the media name
      Returns:
      the builder instance
    • build

      public Media build()
      Builds a new Media instance with the configured properties.
      Returns:
      a new Media instance
      Throws:
      IllegalArgumentException - if mimeType or data are null