diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/image/OpenAiImageClientIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/image/OpenAiImageClientIT.java index bcc29dc3d..bfdcbff8a 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/image/OpenAiImageClientIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/image/OpenAiImageClientIT.java @@ -32,9 +32,12 @@ public class OpenAiImageClientIT extends AbstractIT { @Test void imageAsUrlTest() { - var options = ImageOptionsBuilder.builder().withHeight(256).withWidth(256).build(); + var options = ImageOptionsBuilder.builder().withHeight(1024).withWidth(1024).build(); - ImagePrompt imagePrompt = new ImagePrompt("Create an image of a mini golden doodle dog.", options); + var instructions = """ + A light cream colored mini golden doodle with a sign that contains the message "I'm on my way to BARCADE!"."""; + + ImagePrompt imagePrompt = new ImagePrompt(instructions, options); ImageResponse imageResponse = openaiImageClient.call(imagePrompt); @@ -46,6 +49,7 @@ public class OpenAiImageClientIT extends AbstractIT { var generation = imageResponse.getResult(); Image image = generation.getOutput(); assertThat(image.getUrl()).isNotEmpty(); + // System.out.println(image.getUrl()); assertThat(image.getB64Json()).isNull(); var imageGenerationMetadata = generation.getMetadata(); diff --git a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageClient.java b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageClient.java index edd67c532..887dc598f 100644 --- a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageClient.java +++ b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageClient.java @@ -1,3 +1,18 @@ +/* + * Copyright 2023-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai; import org.slf4j.Logger; @@ -13,6 +28,10 @@ import org.springframework.util.Assert; import java.util.List; import java.util.stream.Collectors; +/** + * StabilityAiImageClient is a class that implements the ImageClient interface. It + * provides a client for calling the StabilityAI image generation API. + */ public class StabilityAiImageClient implements ImageClient { private final Logger logger = LoggerFactory.getLogger(getClass()); diff --git a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageGenerationMetadata.java b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageGenerationMetadata.java index 8eeb4be9a..2c0fac55a 100644 --- a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageGenerationMetadata.java +++ b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageGenerationMetadata.java @@ -1,9 +1,28 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai; import org.springframework.ai.image.ImageGenerationMetadata; import java.util.Objects; +/** + * Represents metadata associated with the image generation process in the StabilityAI + * framework. + */ public class StabilityAiImageGenerationMetadata implements ImageGenerationMetadata { private String finishReason; diff --git a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StyleEnum.java b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StyleEnum.java new file mode 100644 index 000000000..d8f194ac2 --- /dev/null +++ b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StyleEnum.java @@ -0,0 +1,40 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.ai.stabilityai; + +/** + * Enum representing different styles for images. + */ +public enum StyleEnum { + + THREE_D_MODEL("3d-model"), ANALOG_FILM("analog-film"), ANIME("anime"), CINEMATIC("cinematic"), + COMIC_BOOK("comic-book"), DIGITAL_ART("digital-art"), ENHANCE("enhance"), FANTASY_ART("fantasy-art"), + ISOMETRIC("isometric"), LINE_ART("line-art"), LOW_POLY("low-poly"), MODELING_COMPOUND("modeling-compound"), + NEON_PUNK("neon-punk"), ORIGAMI("origami"), PHOTOGRAPHIC("photographic"), PIXEL_ART("pixel-art"), + TILE_TEXTURE("tile-texture"); + + private final String text; + + StyleEnum(final String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + +} \ No newline at end of file diff --git a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiApi.java b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiApi.java index 9e15cec7f..c4913ccbe 100644 --- a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiApi.java +++ b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiApi.java @@ -1,3 +1,18 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai.api; import com.fasterxml.jackson.annotation.JsonInclude; @@ -14,6 +29,9 @@ import java.io.IOException; import java.util.List; import java.util.function.Consumer; +/** + * Represents the StabilityAI API. + */ public class StabilityAiApi { public static final String DEFAULT_IMAGE_MODEL = "stable-diffusion-v1-6"; diff --git a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptions.java b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptions.java index 358cfd8bc..da2fc26ba 100644 --- a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptions.java +++ b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptions.java @@ -1,7 +1,26 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai.api; import org.springframework.ai.image.ImageOptions; +/** + * StabilityAiImageOptions is an interface that extends ImageOptions. It provides + * additional stability AI specific image options. + */ public interface StabilityAiImageOptions extends ImageOptions { Float getCfgScale(); diff --git a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsBuilder.java b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsBuilder.java index 17f5bb9be..be3fb75ff 100644 --- a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsBuilder.java +++ b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsBuilder.java @@ -1,5 +1,27 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai.api; +import org.springframework.ai.stabilityai.StyleEnum; + +/** + * The StabilityAiImageOptionsBuilder class provides a convenient way to construct an + * instance of StabilityAiImageOptions. by allowing you to chain multiple method calls to + * set the desired options. + */ public class StabilityAiImageOptionsBuilder { private StabilityAiImageOptionsImpl options; @@ -72,6 +94,11 @@ public class StabilityAiImageOptionsBuilder { return this; } + public StabilityAiImageOptionsBuilder withStylePreset(StyleEnum styleEnum) { + options.setStylePreset(styleEnum.toString()); + return this; + } + public StabilityAiImageOptions build() { return options; } diff --git a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsImpl.java b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsImpl.java index 0f7213ea8..430f325f1 100644 --- a/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsImpl.java +++ b/models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiImageOptionsImpl.java @@ -1,3 +1,18 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai.api; public class StabilityAiImageOptionsImpl implements StabilityAiImageOptions { diff --git a/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiApiIT.java b/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiApiIT.java index d70f0f071..2e8c2454d 100644 --- a/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiApiIT.java +++ b/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiApiIT.java @@ -1,3 +1,18 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai; import org.junit.jupiter.api.Test; diff --git a/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageClientIT.java b/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageClientIT.java index ea6f74d57..980e63abf 100644 --- a/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageClientIT.java +++ b/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageClientIT.java @@ -1,9 +1,26 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.springframework.ai.image.*; import org.springframework.ai.stabilityai.api.StabilityAiApi; +import org.springframework.ai.stabilityai.api.StabilityAiImageOptions; +import org.springframework.ai.stabilityai.api.StabilityAiImageOptionsBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -24,8 +41,15 @@ public class StabilityAiImageClientIT { @Test void imageAsBase64Test() throws IOException { - ImagePrompt imagePrompt = new ImagePrompt( - "A light cream colored mini golden doodle holding a sign that says 'I want to go with you on vacation!'"); + + StabilityAiImageOptions imageOptions = StabilityAiImageOptionsBuilder.builder() + .withStylePreset(StyleEnum.PHOTOGRAPHIC) + .build(); + + var instructions = """ + A light cream colored mini golden doodle with a sign that contains the message "I'm on my way to BARCADE!"."""; + + ImagePrompt imagePrompt = new ImagePrompt(instructions, imageOptions); ImageResponse imageResponse = this.stabilityAiImageClient.call(imagePrompt); @@ -34,7 +58,7 @@ public class StabilityAiImageClientIT { assertThat(image.getB64Json()).isNotEmpty(); - writeFile(image); + // writeFile(image); } private static void writeFile(Image image) throws IOException { diff --git a/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageTestConfiguration.java b/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageTestConfiguration.java index a4ff9ed03..268b184f3 100644 --- a/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageTestConfiguration.java +++ b/models/spring-ai-stabilityai/src/test/java/org/springframework/ai/stabilityai/StabilityAiImageTestConfiguration.java @@ -1,3 +1,18 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.ai.stabilityai; import org.springframework.ai.stabilityai.api.StabilityAiApi;