Skip to content

Commit

Permalink
Support the Imagen image generation model from Google Cloud Vertex AI (
Browse files Browse the repository at this point in the history
  • Loading branch information
glaforge authored Jan 10, 2024
1 parent 0f3efdc commit f2b0c9f
Show file tree
Hide file tree
Showing 6 changed files with 636 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,19 @@ public static int ensureBetween(Integer i, int min, int max, String name) {
}
return i;
}
/**
* Ensures that the given Long value is in {@code [min, max]}.
* @param i The value to check.
* @param min The minimum value.
* @param max The maximum value.
* @param name The value name to be used in the exception.
* @return The value if it is in {@code [min, max]}.
* @throws IllegalArgumentException if the value is not in {@code [min, max]}.
*/
public static long ensureBetween(Long i, long min, long max, String name) {
if (i == null || i < min || i > max) {
throw illegalArgument("%s must be between %s and %s, but is: %s", name, min, max, i);
}
return i;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,28 @@ public interface ImageModel {
default Response<List<Image>> generate(String prompt, int n) {
throw new IllegalArgumentException("Operation is not supported");
}

/**
* Given an existing image, edit this image following the given prompt.
*
* @param image The image to be edited.
* @param prompt The prompt to edit the image.
* @return The generated image Response.
*/
default Response<Image> edit(Image image, String prompt) {
throw new IllegalArgumentException("Operation is not supported");
}

/**
* 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.
*
* @param image The image to be edited.
* @param mask The image mask to apply to delimit the area to edit.
* @param prompt The prompt to edit the image.
* @return The generated image Response.
*/
default Response<Image> edit(Image image, Image mask, String prompt) {
throw new IllegalArgumentException("Operation is not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public void test_not_supported() {
assertThatThrownBy(() -> model.generate("prompt", 1))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Operation is not supported");

assertThatThrownBy(() -> model.edit(null, "prompt"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Operation is not supported");

assertThatThrownBy(() -> model.edit(null, null, "prompt"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Operation is not supported");
}

@Test
Expand Down
Loading

0 comments on commit f2b0c9f

Please sign in to comment.