Class Media
Media objects can be used in the UserMessage class to attach various types of content like images, documents, or videos. When interacting with AI models, the id and name fields help track and reference specific media objects.
The id field is typically assigned by AI models when they reference previously provided media.
The name field can be used to provide a descriptive identifier to the model, though care should be taken to avoid prompt injection vulnerabilities. For amazon AWS the name must only contain:
- Alphanumeric characters
- Whitespace characters (no more than one in a row)
- Hyphens
- Parentheses
- Square brackets
If no name is provided, one will be automatically generated using the pattern:
{mimeType.subtype}-{UUID}
This class includes a Media.Format
inner class that provides commonly used MIME types
as constants, organized by content category (documents, videos, images). These formats
can be used when constructing Media objects to ensure correct MIME type specification.
This class is used as a parameter in the constructor of the UserMessage class.
- Since:
- 1.0.0
- Author:
- Christian Tzolov, Mark Pollack
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builder class for Media.static class
Common media formats. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic final Media.Builder
builder()
Creates a new Media builder.getData()
Get the media data objectbyte[]
Get the media data as a byte arraygetId()
Get the media idorg.springframework.util.MimeType
Get the media MIME typegetName()
-
Constructor Details
-
Media
Create a new Media instance.- Parameters:
mimeType
- the media MIME typeurl
- the URL for the media data
-
Media
public Media(org.springframework.util.MimeType mimeType, org.springframework.core.io.Resource resource) Create a new Media instance.- Parameters:
mimeType
- the media MIME typeresource
- the media resource
-
Media
@Deprecated(since="1.0.0.M5") public Media(org.springframework.util.MimeType mimeType, org.springframework.core.io.Resource resource, String id) Deprecated.UseMedia.Builder
instead.Create a new Media instance.- Parameters:
mimeType
- the media MIME typeresource
- the media resourceid
- the media id
-
-
Method Details
-
builder
Creates a new Media builder.- Returns:
- a new Media builder instance
-
getMimeType
public org.springframework.util.MimeType getMimeType()Get the media MIME type- Returns:
- the media MIME type
-
getData
Get the media data object- Returns:
- a java.net.URL.toString() or a byte[]
-
getDataAsByteArray
public byte[] getDataAsByteArray()Get the media data as a byte array- Returns:
- the media data as a byte array
-
getId
Get the media id- Returns:
- the media id
-
getName
-
Media.Builder
instead.