Skip to content

Commit e901d12

Browse files
committed
Refactor Stability AI Image options builder methods
- Deprecate builder methods with the prefix `with` - Update docs and references
1 parent d77c950 commit e901d12

File tree

8 files changed

+278
-72
lines changed

8 files changed

+278
-72
lines changed

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@ public StabilityAiImageModel(StabilityAiApi stabilityAiApi, StabilityAiImageOpti
5555
private static StabilityAiApi.GenerateImageRequest getGenerateImageRequest(ImagePrompt stabilityAiImagePrompt,
5656
StabilityAiImageOptions optionsToUse) {
5757
return new StabilityAiApi.GenerateImageRequest.Builder()
58-
.withTextPrompts(stabilityAiImagePrompt.getInstructions()
58+
.textPrompts(stabilityAiImagePrompt.getInstructions()
5959
.stream()
6060
.map(message -> new StabilityAiApi.GenerateImageRequest.TextPrompts(message.getText(),
6161
message.getWeight()))
6262
.collect(Collectors.toList()))
63-
.withHeight(optionsToUse.getHeight())
64-
.withWidth(optionsToUse.getWidth())
65-
.withCfgScale(optionsToUse.getCfgScale())
66-
.withClipGuidancePreset(optionsToUse.getClipGuidancePreset())
67-
.withSampler(optionsToUse.getSampler())
68-
.withSamples(optionsToUse.getN())
69-
.withSeed(optionsToUse.getSeed())
70-
.withSteps(optionsToUse.getSteps())
71-
.withStylePreset(optionsToUse.getStylePreset())
63+
.height(optionsToUse.getHeight())
64+
.width(optionsToUse.getWidth())
65+
.cfgScale(optionsToUse.getCfgScale())
66+
.clipGuidancePreset(optionsToUse.getClipGuidancePreset())
67+
.sampler(optionsToUse.getSampler())
68+
.samples(optionsToUse.getN())
69+
.seed(optionsToUse.getSeed())
70+
.steps(optionsToUse.getSteps())
71+
.stylePreset(optionsToUse.getStylePreset())
7272
.build();
7373
}
7474

@@ -124,32 +124,31 @@ StabilityAiImageOptions mergeOptions(ImageOptions runtimeOptions, StabilityAiIma
124124
}
125125
StabilityAiImageOptions.Builder builder = StabilityAiImageOptions.builder()
126126
// Handle portable image options
127-
.withModel(ModelOptionsUtils.mergeOption(runtimeOptions.getModel(), defaultOptions.getModel()))
128-
.withN(ModelOptionsUtils.mergeOption(runtimeOptions.getN(), defaultOptions.getN()))
129-
.withResponseFormat(ModelOptionsUtils.mergeOption(runtimeOptions.getResponseFormat(),
127+
.model(ModelOptionsUtils.mergeOption(runtimeOptions.getModel(), defaultOptions.getModel()))
128+
.N(ModelOptionsUtils.mergeOption(runtimeOptions.getN(), defaultOptions.getN()))
129+
.responseFormat(ModelOptionsUtils.mergeOption(runtimeOptions.getResponseFormat(),
130130
defaultOptions.getResponseFormat()))
131-
.withWidth(ModelOptionsUtils.mergeOption(runtimeOptions.getWidth(), defaultOptions.getWidth()))
132-
.withHeight(ModelOptionsUtils.mergeOption(runtimeOptions.getHeight(), defaultOptions.getHeight()))
133-
.withStylePreset(ModelOptionsUtils.mergeOption(runtimeOptions.getStyle(), defaultOptions.getStyle()))
131+
.width(ModelOptionsUtils.mergeOption(runtimeOptions.getWidth(), defaultOptions.getWidth()))
132+
.height(ModelOptionsUtils.mergeOption(runtimeOptions.getHeight(), defaultOptions.getHeight()))
133+
.stylePreset(ModelOptionsUtils.mergeOption(runtimeOptions.getStyle(), defaultOptions.getStyle()))
134134
// Always set the stability-specific defaults
135-
.withCfgScale(defaultOptions.getCfgScale())
136-
.withClipGuidancePreset(defaultOptions.getClipGuidancePreset())
137-
.withSampler(defaultOptions.getSampler())
138-
.withSeed(defaultOptions.getSeed())
139-
.withSteps(defaultOptions.getSteps())
140-
.withStylePreset(defaultOptions.getStylePreset());
135+
.cfgScale(defaultOptions.getCfgScale())
136+
.clipGuidancePreset(defaultOptions.getClipGuidancePreset())
137+
.sampler(defaultOptions.getSampler())
138+
.seed(defaultOptions.getSeed())
139+
.steps(defaultOptions.getSteps())
140+
.stylePreset(defaultOptions.getStylePreset());
141141
if (runtimeOptions instanceof StabilityAiImageOptions) {
142142
StabilityAiImageOptions stabilityOptions = (StabilityAiImageOptions) runtimeOptions;
143143
// Handle Stability AI specific image options
144144
builder
145-
.withCfgScale(
146-
ModelOptionsUtils.mergeOption(stabilityOptions.getCfgScale(), defaultOptions.getCfgScale()))
147-
.withClipGuidancePreset(ModelOptionsUtils.mergeOption(stabilityOptions.getClipGuidancePreset(),
145+
.cfgScale(ModelOptionsUtils.mergeOption(stabilityOptions.getCfgScale(), defaultOptions.getCfgScale()))
146+
.clipGuidancePreset(ModelOptionsUtils.mergeOption(stabilityOptions.getClipGuidancePreset(),
148147
defaultOptions.getClipGuidancePreset()))
149-
.withSampler(ModelOptionsUtils.mergeOption(stabilityOptions.getSampler(), defaultOptions.getSampler()))
150-
.withSeed(ModelOptionsUtils.mergeOption(stabilityOptions.getSeed(), defaultOptions.getSeed()))
151-
.withSteps(ModelOptionsUtils.mergeOption(stabilityOptions.getSteps(), defaultOptions.getSteps()))
152-
.withStylePreset(ModelOptionsUtils.mergeOption(stabilityOptions.getStylePreset(),
148+
.sampler(ModelOptionsUtils.mergeOption(stabilityOptions.getSampler(), defaultOptions.getSampler()))
149+
.seed(ModelOptionsUtils.mergeOption(stabilityOptions.getSeed(), defaultOptions.getSeed()))
150+
.steps(ModelOptionsUtils.mergeOption(stabilityOptions.getSteps(), defaultOptions.getSteps()))
151+
.stylePreset(ModelOptionsUtils.mergeOption(stabilityOptions.getStylePreset(),
153152
defaultOptions.getStylePreset()));
154153
}
155154

models/spring-ai-stability-ai/src/main/java/org/springframework/ai/stabilityai/api/StabilityAiApi.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,51 +137,141 @@ public Builder() {
137137

138138
}
139139

140+
public Builder textPrompts(List<TextPrompts> textPrompts) {
141+
this.textPrompts = textPrompts;
142+
return this;
143+
}
144+
145+
public Builder height(Integer height) {
146+
this.height = height;
147+
return this;
148+
}
149+
150+
public Builder width(Integer width) {
151+
this.width = width;
152+
return this;
153+
}
154+
155+
public Builder cfgScale(Float cfgScale) {
156+
this.cfgScale = cfgScale;
157+
return this;
158+
}
159+
160+
public Builder clipGuidancePreset(String clipGuidancePreset) {
161+
this.clipGuidancePreset = clipGuidancePreset;
162+
return this;
163+
}
164+
165+
public Builder sampler(String sampler) {
166+
this.sampler = sampler;
167+
return this;
168+
}
169+
170+
public Builder samples(Integer samples) {
171+
this.samples = samples;
172+
return this;
173+
}
174+
175+
public Builder seed(Long seed) {
176+
this.seed = seed;
177+
return this;
178+
}
179+
180+
public Builder steps(Integer steps) {
181+
this.steps = steps;
182+
return this;
183+
}
184+
185+
public Builder stylePreset(String stylePreset) {
186+
this.stylePreset = stylePreset;
187+
return this;
188+
}
189+
190+
/**
191+
* @deprecated use {@link #textPrompts(List)} instead.
192+
*/
193+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
140194
public Builder withTextPrompts(List<TextPrompts> textPrompts) {
141195
this.textPrompts = textPrompts;
142196
return this;
143197
}
144198

199+
/**
200+
* @deprecated use {@link #height(Integer)} instead.
201+
*/
202+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
145203
public Builder withHeight(Integer height) {
146204
this.height = height;
147205
return this;
148206
}
149207

208+
/**
209+
* @deprecated use {@link #width(Integer)} instead.
210+
*/
211+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
150212
public Builder withWidth(Integer width) {
151213
this.width = width;
152214
return this;
153215
}
154216

217+
/**
218+
* @deprecated use {@link #cfgScale(Float)} instead.
219+
*/
220+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
155221
public Builder withCfgScale(Float cfgScale) {
156222
this.cfgScale = cfgScale;
157223
return this;
158224
}
159225

226+
/**
227+
* @deprecated use {@link #clipGuidancePreset(String)} instead.
228+
*/
229+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
160230
public Builder withClipGuidancePreset(String clipGuidancePreset) {
161231
this.clipGuidancePreset = clipGuidancePreset;
162232
return this;
163233
}
164234

235+
/**
236+
* @deprecated use {@link #sampler(String)} instead.
237+
*/
238+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
165239
public Builder withSampler(String sampler) {
166240
this.sampler = sampler;
167241
return this;
168242
}
169243

244+
/**
245+
* @deprecated use {@link #samples(Integer)} instead.
246+
*/
247+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
170248
public Builder withSamples(Integer samples) {
171249
this.samples = samples;
172250
return this;
173251
}
174252

253+
/**
254+
* @deprecated use {@link #seed(Long)} instead.
255+
*/
256+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
175257
public Builder withSeed(Long seed) {
176258
this.seed = seed;
177259
return this;
178260
}
179261

262+
/**
263+
* @deprecated use {@link #steps(Integer)} instead.
264+
*/
265+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
180266
public Builder withSteps(Integer steps) {
181267
this.steps = steps;
182268
return this;
183269
}
184270

271+
/**
272+
* @deprecated use {@link #stylePreset(String)} instead.
273+
*/
274+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
185275
public Builder withStylePreset(String stylePreset) {
186276
this.stylePreset = stylePreset;
187277
return this;

0 commit comments

Comments
 (0)