Package org.springframework.ai.model
Class Media.Builder
java.lang.Object
org.springframework.ai.model.Media.Builder
- Enclosing class:
- Media
Builder class for Media.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a new Media instance with the configured properties.Sets the media data from any Object.Sets the media data from a URL.data
(org.springframework.core.io.Resource resource) Sets the media data from a Resource.Sets the ID for the media object.mimeType
(org.springframework.util.MimeType mimeType) Sets the MIME type for the media object.Sets the name for the media object.
-
Method Details
-
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
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
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
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
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
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
Builds a new Media instance with the configured properties.- Returns:
- a new Media instance
- Throws:
IllegalArgumentException
- if mimeType or data are null
-