Package dev.langchain4j.model.vertexai
Class VertexAiImageModel
java.lang.Object
dev.langchain4j.model.vertexai.VertexAiImageModel
- All Implemented Interfaces:
ImageModel
Image model for the Google Cloud Vertex AI Imagen image generation models.
Supports both versions of Imagen v1 and v2, respectively identified by the model names
imagegeneration@002
and imagegeneration@005
,
and will also work with the upcoming Imagen v3 model,
identified as imagen-3.0-generate-preview-0611
or
imagen-3.0-fast-generate-preview-0611
for faster generation.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Supported aspect ratios: 1:1, 9:16, 16:9, 4:3, and 3:4.static class
static enum
Image style can be specified forimagen@002
.static enum
Supported mime types: only PNG and JPEG image formats can be generated.static enum
Specify whether persons are allowed to be generated. -
Constructor Summary
ConstructorDescriptionVertexAiImageModel
(String endpoint, String project, String location, String publisher, String modelName, Long seed, String language, Integer guidanceScale, String negativePrompt, VertexAiImageModel.ImageStyle sampleImageStyle, Integer sampleImageSize, VertexAiImageModel.AspectRatio aspectRatio, VertexAiImageModel.PersonGeneration personGeneration, Integer maxRetries, VertexAiImageModel.MimeType mimeType, Integer compressionQuality, Boolean addWatermark, String cloudStorageBucket, Boolean withPersisting, Path persistTo, Boolean logRequests, Boolean logResponses) Constructor of the Imagen image generation model. -
Method Summary
Modifier and TypeMethodDescriptionstatic VertexAiImageModel.Builder
builder()
Given an existing image, edit this image following the given prompt and apply the changes only to the part of the image specified by the given mask.Given an existing image, edit this image following the given prompt.Given a prompt, generate an image.Given a prompt, generate n images.
-
Constructor Details
-
VertexAiImageModel
public VertexAiImageModel(String endpoint, String project, String location, String publisher, String modelName, Long seed, String language, Integer guidanceScale, String negativePrompt, VertexAiImageModel.ImageStyle sampleImageStyle, Integer sampleImageSize, VertexAiImageModel.AspectRatio aspectRatio, VertexAiImageModel.PersonGeneration personGeneration, Integer maxRetries, VertexAiImageModel.MimeType mimeType, Integer compressionQuality, Boolean addWatermark, String cloudStorageBucket, Boolean withPersisting, Path persistTo, Boolean logRequests, Boolean logResponses) Constructor of the Imagen image generation model.- Parameters:
endpoint
- the base URL of the API (eg.https://us-central1-aiplatform.googleapis.com/v1/
)project
- the Google Cloud Project IDlocation
- the cloud region (eg.us-central1
)publisher
- the publisher of the model (google
for Imagen)modelName
- the name of the image model (imagegeneration@002
,imagegeneration@005
,imagen-3.0-generate-preview-0611
,imagen-3.0-fast-generate-preview-0611
)seed
- a fixed random seed number between 0 and 2^32-1language
- the spoken language used for the promptguidanceScale
- an integer that represents the strength of the edit to make (0-9: low, 10-20: medium, 21+: high)negativePrompt
- a negative prompt to specify what you don't want to see in the generated imagesampleImageStyle
- the style of the image for Imagen v1, see theImageStyle
enum for referencesampleImageSize
- the size of the images to generateaspectRatio
- the aspect ratio of the image, whether square, portrait or landscapepersonGeneration
- specify if it is allowed to generate persons (none, only adults, all)maxRetries
- number of times to retry in case of error (default: 3)mimeType
- specify the mime type of the image to generate (image/png by default, but image/jpeg possible)compressionQuality
- when generating a JPEG image, specify the compression quality (ex: 80 for good quality)addWatermark
- true to generate a watermark so users can know it's an AI generated image (default to false for Imagen v1 and v2, but to true for Imagen v3)cloudStorageBucket
- URI of the Google Cloud Storage bucket where to persist the generated imagewithPersisting
- true if the generated images should be persisted on the local file systempersistTo
- thePath
of the directory that should contain the generated images
-
-
Method Details
-
generate
Description copied from interface:ImageModel
Given a prompt, generate an image.- Specified by:
generate
in interfaceImageModel
- Parameters:
prompt
- The prompt to generate an image from.- Returns:
- The generated image Response.
-
generate
Description copied from interface:ImageModel
Given a prompt, generate n images.Not supported by all models; as explicit support is needed to generate different images from the same prompt.
- Specified by:
generate
in interfaceImageModel
- Parameters:
prompt
- The prompt to generate images from.n
- The number of images to generate.- Returns:
- The generated images Response.
-
edit
Description copied from interface:ImageModel
Given an existing image, edit this image following the given prompt.- Specified by:
edit
in interfaceImageModel
- Parameters:
image
- The image to be edited.prompt
- The prompt to edit the image.- Returns:
- The generated image Response.
-
edit
Description copied from interface:ImageModel
Given an existing image, edit this image following the given prompt and apply the changes only to the part of the image specified by the given mask.- Specified by:
edit
in interfaceImageModel
- Parameters:
image
- The image to be edited.mask
- The image mask to apply to delimit the area to edit.prompt
- The prompt to edit the image.- Returns:
- The generated image Response.
-
builder
-