Skip to content

Commit 08b9c25

Browse files
committed
Refactor builder methods of Moderation package
- Update Moderation, Generation, Categories, CategoryScores' builder method - deprecate the existing builder methods with the prefix `with` and replace them without the prefix
1 parent d3d34c9 commit 08b9c25

File tree

5 files changed

+248
-0
lines changed

5 files changed

+248
-0
lines changed

spring-ai-core/src/main/java/org/springframework/ai/moderation/Categories.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* false (indicating that the content does not belong to the category).
2525
*
2626
* @author Ahmed Yousri
27+
* @author Ilayaperumal Gopinathan
2728
* @since 1.0.0
2829
*/
2930
public final class Categories {
@@ -168,56 +169,155 @@ public static class Builder {
168169

169170
private boolean violence;
170171

172+
public Builder sexual(boolean sexual) {
173+
this.sexual = sexual;
174+
return this;
175+
}
176+
177+
public Builder hate(boolean hate) {
178+
this.hate = hate;
179+
return this;
180+
}
181+
182+
public Builder harassment(boolean harassment) {
183+
this.harassment = harassment;
184+
return this;
185+
}
186+
187+
public Builder selfHarm(boolean selfHarm) {
188+
this.selfHarm = selfHarm;
189+
return this;
190+
}
191+
192+
public Builder sexualMinors(boolean sexualMinors) {
193+
this.sexualMinors = sexualMinors;
194+
return this;
195+
}
196+
197+
public Builder hateThreatening(boolean hateThreatening) {
198+
this.hateThreatening = hateThreatening;
199+
return this;
200+
}
201+
202+
public Builder violenceGraphic(boolean violenceGraphic) {
203+
this.violenceGraphic = violenceGraphic;
204+
return this;
205+
}
206+
207+
public Builder selfHarmIntent(boolean selfHarmIntent) {
208+
this.selfHarmIntent = selfHarmIntent;
209+
return this;
210+
}
211+
212+
public Builder selfHarmInstructions(boolean selfHarmInstructions) {
213+
this.selfHarmInstructions = selfHarmInstructions;
214+
return this;
215+
}
216+
217+
public Builder harassmentThreatening(boolean harassmentThreatening) {
218+
this.harassmentThreatening = harassmentThreatening;
219+
return this;
220+
}
221+
222+
public Builder violence(boolean violence) {
223+
this.violence = violence;
224+
return this;
225+
}
226+
227+
/**
228+
* @deprecated use {@link #sexual(boolean)} instead.
229+
*/
230+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
171231
public Builder withSexual(boolean sexual) {
172232
this.sexual = sexual;
173233
return this;
174234
}
175235

236+
/**
237+
* @deprecated use {@link #hate(boolean)} instead.
238+
*/
239+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
176240
public Builder withHate(boolean hate) {
177241
this.hate = hate;
178242
return this;
179243
}
180244

245+
/**
246+
* @deprecated use {@link #harassment(boolean)} instead.
247+
*/
248+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
181249
public Builder withHarassment(boolean harassment) {
182250
this.harassment = harassment;
183251
return this;
184252
}
185253

254+
/**
255+
* @deprecated use {@link #selfHarm(boolean)} instead.
256+
*/
257+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
186258
public Builder withSelfHarm(boolean selfHarm) {
187259
this.selfHarm = selfHarm;
188260
return this;
189261
}
190262

263+
/**
264+
* @deprecated use {@link #sexualMinors(boolean)} instead.
265+
*/
266+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
191267
public Builder withSexualMinors(boolean sexualMinors) {
192268
this.sexualMinors = sexualMinors;
193269
return this;
194270
}
195271

272+
/**
273+
* @deprecated use {@link #hateThreatening(boolean)} instead.
274+
*/
275+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
196276
public Builder withHateThreatening(boolean hateThreatening) {
197277
this.hateThreatening = hateThreatening;
198278
return this;
199279
}
200280

281+
/**
282+
* @deprecated use {@link #violenceGraphic(boolean)} instead.
283+
*/
284+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
201285
public Builder withViolenceGraphic(boolean violenceGraphic) {
202286
this.violenceGraphic = violenceGraphic;
203287
return this;
204288
}
205289

290+
/**
291+
* @deprecated use {@link #selfHarmIntent(boolean)} instead.
292+
*/
293+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
206294
public Builder withSelfHarmIntent(boolean selfHarmIntent) {
207295
this.selfHarmIntent = selfHarmIntent;
208296
return this;
209297
}
210298

299+
/**
300+
* @deprecated use {@link #selfHarmInstructions(boolean)} instead.
301+
*/
302+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
211303
public Builder withSelfHarmInstructions(boolean selfHarmInstructions) {
212304
this.selfHarmInstructions = selfHarmInstructions;
213305
return this;
214306
}
215307

308+
/**
309+
* @deprecated use {@link #harassmentThreatening(boolean)} instead.
310+
*/
311+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
216312
public Builder withHarassmentThreatening(boolean harassmentThreatening) {
217313
this.harassmentThreatening = harassmentThreatening;
218314
return this;
219315
}
220316

317+
/**
318+
* @deprecated use {@link #violence(boolean)} instead.
319+
*/
320+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
221321
public Builder withViolence(boolean violence) {
222322
this.violence = violence;
223323
return this;

spring-ai-core/src/main/java/org/springframework/ai/moderation/CategoryScores.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* content in each respective category.
2525
*
2626
* @author Ahmed Yousri
27+
* @author Ilayaperumal Gopinathan
2728
* @since 1.0.0
2829
*/
2930
public final class CategoryScores {
@@ -173,56 +174,155 @@ public static class Builder {
173174

174175
private double violence;
175176

177+
public Builder sexual(double sexual) {
178+
this.sexual = sexual;
179+
return this;
180+
}
181+
182+
public Builder hate(double hate) {
183+
this.hate = hate;
184+
return this;
185+
}
186+
187+
public Builder harassment(double harassment) {
188+
this.harassment = harassment;
189+
return this;
190+
}
191+
192+
public Builder selfHarm(double selfHarm) {
193+
this.selfHarm = selfHarm;
194+
return this;
195+
}
196+
197+
public Builder sexualMinors(double sexualMinors) {
198+
this.sexualMinors = sexualMinors;
199+
return this;
200+
}
201+
202+
public Builder hateThreatening(double hateThreatening) {
203+
this.hateThreatening = hateThreatening;
204+
return this;
205+
}
206+
207+
public Builder violenceGraphic(double violenceGraphic) {
208+
this.violenceGraphic = violenceGraphic;
209+
return this;
210+
}
211+
212+
public Builder selfHarmIntent(double selfHarmIntent) {
213+
this.selfHarmIntent = selfHarmIntent;
214+
return this;
215+
}
216+
217+
public Builder selfHarmInstructions(double selfHarmInstructions) {
218+
this.selfHarmInstructions = selfHarmInstructions;
219+
return this;
220+
}
221+
222+
public Builder harassmentThreatening(double harassmentThreatening) {
223+
this.harassmentThreatening = harassmentThreatening;
224+
return this;
225+
}
226+
227+
public Builder violence(double violence) {
228+
this.violence = violence;
229+
return this;
230+
}
231+
232+
/**
233+
* @deprecated use {@link #sexual(double)} instead.
234+
*/
235+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
176236
public Builder withSexual(double sexual) {
177237
this.sexual = sexual;
178238
return this;
179239
}
180240

241+
/**
242+
* @deprecated use {@link #hate(double)} instead.
243+
*/
244+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
181245
public Builder withHate(double hate) {
182246
this.hate = hate;
183247
return this;
184248
}
185249

250+
/**
251+
* @deprecated use {@link #harassment(double)} instead.
252+
*/
253+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
186254
public Builder withHarassment(double harassment) {
187255
this.harassment = harassment;
188256
return this;
189257
}
190258

259+
/**
260+
* @deprecated use {@link #selfHarm(double)} instead.
261+
*/
262+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
191263
public Builder withSelfHarm(double selfHarm) {
192264
this.selfHarm = selfHarm;
193265
return this;
194266
}
195267

268+
/**
269+
* @deprecated use {@link #sexualMinors(double)} instead.
270+
*/
271+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
196272
public Builder withSexualMinors(double sexualMinors) {
197273
this.sexualMinors = sexualMinors;
198274
return this;
199275
}
200276

277+
/**
278+
* @deprecated use {@link #hateThreatening(double)} instead.
279+
*/
280+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
201281
public Builder withHateThreatening(double hateThreatening) {
202282
this.hateThreatening = hateThreatening;
203283
return this;
204284
}
205285

286+
/**
287+
* @deprecated use {@link #violenceGraphic(double)} instead.
288+
*/
289+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
206290
public Builder withViolenceGraphic(double violenceGraphic) {
207291
this.violenceGraphic = violenceGraphic;
208292
return this;
209293
}
210294

295+
/**
296+
* @deprecated use {@link #selfHarmIntent(double)} instead.
297+
*/
298+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
211299
public Builder withSelfHarmIntent(double selfHarmIntent) {
212300
this.selfHarmIntent = selfHarmIntent;
213301
return this;
214302
}
215303

304+
/**
305+
* @deprecated use {@link #selfHarmInstructions(double)} instead.
306+
*/
307+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
216308
public Builder withSelfHarmInstructions(double selfHarmInstructions) {
217309
this.selfHarmInstructions = selfHarmInstructions;
218310
return this;
219311
}
220312

313+
/**
314+
* @deprecated use {@link #harassmentThreatening(double)} instead.
315+
*/
316+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
221317
public Builder withHarassmentThreatening(double harassmentThreatening) {
222318
this.harassmentThreatening = harassmentThreatening;
223319
return this;
224320
}
225321

322+
/**
323+
* @deprecated use {@link #violence(double)} instead.
324+
*/
325+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
226326
public Builder withViolence(double violence) {
227327
this.violence = violence;
228328
return this;

spring-ai-core/src/main/java/org/springframework/ai/moderation/Generation.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public Generation(Moderation moderation, ModerationGenerationMetadata moderation
4545
this.moderationGenerationMetadata = moderationGenerationMetadata;
4646
}
4747

48+
public Generation generationMetadata(@Nullable ModerationGenerationMetadata moderationGenerationMetadata) {
49+
this.moderationGenerationMetadata = moderationGenerationMetadata;
50+
return this;
51+
}
52+
53+
/**
54+
* @deprecated use {@link #generationMetadata(ModerationGenerationMetadata)} instead.
55+
*/
56+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
4857
public Generation withGenerationMetadata(@Nullable ModerationGenerationMetadata moderationGenerationMetadata) {
4958
this.moderationGenerationMetadata = moderationGenerationMetadata;
5059
return this;

spring-ai-core/src/main/java/org/springframework/ai/moderation/Moderation.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Moderation, use the Builder class.
2727
*
2828
* @author Ahmed Yousri
29+
* @author Ilayaperumal Gopinathan
2930
* @since 1.0.0
3031
*/
3132
public final class Moderation {
@@ -90,16 +91,43 @@ public static class Builder {
9091

9192
private List<ModerationResult> moderationResultList;
9293

94+
public Builder id(String id) {
95+
this.id = id;
96+
return this;
97+
}
98+
99+
public Builder model(String model) {
100+
this.model = model;
101+
return this;
102+
}
103+
104+
public Builder results(List<ModerationResult> results) {
105+
this.moderationResultList = results;
106+
return this;
107+
}
108+
109+
/**
110+
* @deprecated use {@link #id(String)} instead.
111+
*/
112+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
93113
public Builder withId(String id) {
94114
this.id = id;
95115
return this;
96116
}
97117

118+
/**
119+
* @deprecated use {@link #model(String)} instead.
120+
*/
121+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
98122
public Builder withModel(String model) {
99123
this.model = model;
100124
return this;
101125
}
102126

127+
/**
128+
* @deprecated use {@link #results(List)} instead.
129+
*/
130+
@Deprecated(forRemoval = true, since = "1.0.0-M5")
103131
public Builder withResults(List<ModerationResult> results) {
104132
this.moderationResultList = results;
105133
return this;

0 commit comments

Comments
 (0)