Skip to content

Commit 1eb5055

Browse files
mjkhubilayaperumalg
authored andcommitted
Refactor builder pattern in VertexAiGeminiSafetySetting
Replace builder-based ctor with full-arg private constructor Signed-off-by: jay <rlaakswo0687@gmail.com>
1 parent 926b4dc commit 1eb5055

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/common/VertexAiGeminiSafetySetting.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
public class VertexAiGeminiSafetySetting {
2020

21+
public static Builder builder() {
22+
return new Builder();
23+
}
24+
2125
/**
2226
* Enum representing different threshold levels for blocking harmful content.
2327
*/
@@ -77,51 +81,30 @@ public int getValue() {
7781

7882
}
7983

80-
private HarmCategory category;
84+
private final HarmCategory category;
8185

82-
private HarmBlockThreshold threshold;
86+
private final HarmBlockThreshold threshold;
8387

84-
private HarmBlockMethod method;
85-
86-
// Default constructor
87-
public VertexAiGeminiSafetySetting() {
88-
this.category = HarmCategory.HARM_CATEGORY_UNSPECIFIED;
89-
this.threshold = HarmBlockThreshold.HARM_BLOCK_THRESHOLD_UNSPECIFIED;
90-
this.method = HarmBlockMethod.HARM_BLOCK_METHOD_UNSPECIFIED;
91-
}
88+
private final HarmBlockMethod method;
9289

93-
// Constructor with all fields
94-
public VertexAiGeminiSafetySetting(HarmCategory category, HarmBlockThreshold threshold, HarmBlockMethod method) {
90+
private VertexAiGeminiSafetySetting(HarmCategory category, HarmBlockThreshold threshold, HarmBlockMethod method) {
9591
this.category = category;
9692
this.threshold = threshold;
9793
this.method = method;
9894
}
9995

100-
// Getters and setters
10196
public HarmCategory getCategory() {
10297
return this.category;
10398
}
10499

105-
public void setCategory(HarmCategory category) {
106-
this.category = category;
107-
}
108-
109100
public HarmBlockThreshold getThreshold() {
110101
return this.threshold;
111102
}
112103

113-
public void setThreshold(HarmBlockThreshold threshold) {
114-
this.threshold = threshold;
115-
}
116-
117104
public HarmBlockMethod getMethod() {
118105
return this.method;
119106
}
120107

121-
public void setMethod(HarmBlockMethod method) {
122-
this.method = method;
123-
}
124-
125108
@Override
126109
public String toString() {
127110
return "SafetySetting{" + "category=" + this.category + ", threshold=" + this.threshold + ", method="

models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void googleSearchToolFlash() {
117117
@Test
118118
@Disabled
119119
void testSafetySettings() {
120-
List<VertexAiGeminiSafetySetting> safetySettings = List.of(new VertexAiGeminiSafetySetting.Builder()
120+
List<VertexAiGeminiSafetySetting> safetySettings = List.of(VertexAiGeminiSafetySetting.builder()
121121
.withCategory(VertexAiGeminiSafetySetting.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT)
122122
.withThreshold(VertexAiGeminiSafetySetting.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE)
123123
.build());

0 commit comments

Comments
 (0)