Skip to content

Commit 43dbaf4

Browse files
committed
Add documentation for Image Generation
- Refine StabilityAI classes - Add documentation
1 parent 36278af commit 43dbaf4

File tree

17 files changed

+1007
-323
lines changed

17 files changed

+1007
-323
lines changed

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageOptions.java

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.springframework.ai.image.ImageOptions;
2222
import org.springframework.ai.openai.api.OpenAiImageApi;
2323

24+
import java.util.Objects;
25+
2426
/**
2527
* OpenAI Image API options. OpenAiImageOptions.java
2628
*
@@ -44,6 +46,18 @@ public class OpenAiImageOptions implements ImageOptions {
4446
@JsonProperty("model")
4547
private String model = OpenAiImageApi.DEFAULT_IMAGE_MODEL;
4648

49+
/**
50+
* The width of the generated images. Must be one of 256, 512, or 1024 for dall-e-2.
51+
*/
52+
@JsonProperty("size_width")
53+
private Integer width;
54+
55+
/**
56+
* The height of the generated images. Must be one of 256, 512, or 1024 for dall-e-2.
57+
*/
58+
@JsonProperty("size_height")
59+
private Integer height;
60+
4761
/**
4862
* The quality of the image that will be generated. hd creates images with finer
4963
* details and greater consistency across the image. This param is only supported for
@@ -66,18 +80,6 @@ public class OpenAiImageOptions implements ImageOptions {
6680
@JsonProperty("size")
6781
private String size;
6882

69-
/**
70-
* The width of the generated images. Must be one of 256, 512, or 1024 for dall-e-2.
71-
*/
72-
@JsonProperty("size_width")
73-
private Integer width;
74-
75-
/**
76-
* The height of the generated images. Must be one of 256, 512, or 1024 for dall-e-2.
77-
*/
78-
@JsonProperty("size_height")
79-
private Integer height;
80-
8183
/**
8284
* The style of the generated images. Must be one of vivid or natural. Vivid causes
8385
* the model to lean towards generating hyper-real and dramatic images. Natural causes
@@ -235,4 +237,28 @@ public String getSize() {
235237
return (this.width != null && this.height != null) ? this.width + "x" + this.height : null;
236238
}
237239

240+
@Override
241+
public boolean equals(Object o) {
242+
if (this == o)
243+
return true;
244+
if (!(o instanceof OpenAiImageOptions that))
245+
return false;
246+
return Objects.equals(n, that.n) && Objects.equals(model, that.model) && Objects.equals(width, that.width)
247+
&& Objects.equals(height, that.height) && Objects.equals(quality, that.quality)
248+
&& Objects.equals(responseFormat, that.responseFormat) && Objects.equals(size, that.size)
249+
&& Objects.equals(style, that.style) && Objects.equals(user, that.user);
250+
}
251+
252+
@Override
253+
public int hashCode() {
254+
return Objects.hash(n, model, width, height, quality, responseFormat, size, style, user);
255+
}
256+
257+
@Override
258+
public String toString() {
259+
return "OpenAiImageOptions{" + "n=" + n + ", model='" + model + '\'' + ", width=" + width + ", height=" + height
260+
+ ", quality='" + quality + '\'' + ", responseFormat='" + responseFormat + '\'' + ", size='" + size
261+
+ '\'' + ", style='" + style + '\'' + ", user='" + user + '\'' + '}';
262+
}
263+
238264
}

models/spring-ai-stabilityai/src/main/java/org/springframework/ai/stabilityai/StabilityAiImageClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.springframework.ai.model.ModelOptionsUtils;
2222
import org.springframework.ai.stabilityai.api.StabilityAiApi;
2323
import org.springframework.ai.stabilityai.api.StabilityAiImageOptions;
24-
import org.springframework.ai.stabilityai.api.StabilityAiImageOptionsBuilder;
25-
import org.springframework.ai.stabilityai.api.StabilityAiImageOptionsImpl;
2624
import org.springframework.util.Assert;
2725

2826
import java.util.List;
@@ -41,7 +39,7 @@ public class StabilityAiImageClient implements ImageClient {
4139
private final StabilityAiApi stabilityAiApi;
4240

4341
public StabilityAiImageClient(StabilityAiApi stabilityAiApi) {
44-
this(stabilityAiApi, StabilityAiImageOptionsBuilder.builder().build());
42+
this(stabilityAiApi, StabilityAiImageOptions.builder().build());
4543
}
4644

4745
public StabilityAiImageClient(StabilityAiApi stabilityAiApi, StabilityAiImageOptions options) {
@@ -71,7 +69,7 @@ public ImageResponse call(ImagePrompt imagePrompt) {
7169
// options configured via Autoconfiguration.
7270
// Runtime options overwrite StabilityAiImageClient options
7371
StabilityAiImageOptions optionsToUse = ModelOptionsUtils.merge(runtimeOptions, this.options,
74-
StabilityAiImageOptionsImpl.class);
72+
StabilityAiImageOptions.class);
7573

7674
// Copy the org.springframework.ai.model derived ImagePrompt and ImageOptions data
7775
// types to the data types used in StabilityAiApi
@@ -100,7 +98,7 @@ private static StabilityAiApi.GenerateImageRequest getGenerateImageRequest(Image
10098
.withCfgScale(optionsToUse.getCfgScale())
10199
.withClipGuidancePreset(optionsToUse.getClipGuidancePreset())
102100
.withSampler(optionsToUse.getSampler())
103-
.withSamples(optionsToUse.getSamples())
101+
.withSamples(optionsToUse.getN())
104102
.withSeed(optionsToUse.getSeed())
105103
.withSteps(optionsToUse.getSteps())
106104
.withStylePreset(optionsToUse.getStylePreset())
@@ -118,7 +116,7 @@ private ImageResponse convertResponse(StabilityAiApi.GenerateImageResponse gener
118116
}
119117

120118
private StabilityAiImageOptions convertOptions(ImageOptions runtimeOptions) {
121-
StabilityAiImageOptionsBuilder builder = StabilityAiImageOptionsBuilder.builder();
119+
StabilityAiImageOptions.Builder builder = StabilityAiImageOptions.builder();
122120
if (runtimeOptions == null) {
123121
return builder.build();
124122
}

0 commit comments

Comments
 (0)