Skip to content

Commit 0e1a536

Browse files
committed
Refactor builder pattern in VertexAiGeminiSafetySetting
Signed-off-by: jay <[email protected]>
1 parent 3919204 commit 0e1a536

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

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

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,51 +77,29 @@ public int getValue() {
7777

7878
}
7979

80-
private HarmCategory category;
80+
private final HarmCategory category;
8181

82-
private HarmBlockThreshold threshold;
82+
private final HarmBlockThreshold threshold;
8383

84-
private HarmBlockMethod method;
84+
private final HarmBlockMethod method;
8585

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-
}
9286

93-
// Constructor with all fields
94-
public VertexAiGeminiSafetySetting(HarmCategory category, HarmBlockThreshold threshold, HarmBlockMethod method) {
95-
this.category = category;
96-
this.threshold = threshold;
97-
this.method = method;
87+
private VertexAiGeminiSafetySetting(Builder builder) {
88+
this.category = builder.category;
89+
this.threshold = builder.threshold;
90+
this.method = builder.method;
9891
}
9992

100-
// Getters and setters
10193
public HarmCategory getCategory() {
10294
return this.category;
10395
}
104-
105-
public void setCategory(HarmCategory category) {
106-
this.category = category;
107-
}
108-
10996
public HarmBlockThreshold getThreshold() {
11097
return this.threshold;
11198
}
112-
113-
public void setThreshold(HarmBlockThreshold threshold) {
114-
this.threshold = threshold;
115-
}
116-
11799
public HarmBlockMethod getMethod() {
118100
return this.method;
119101
}
120102

121-
public void setMethod(HarmBlockMethod method) {
122-
this.method = method;
123-
}
124-
125103
@Override
126104
public String toString() {
127105
return "SafetySetting{" + "category=" + this.category + ", threshold=" + this.threshold + ", method="
@@ -180,7 +158,7 @@ public Builder withMethod(HarmBlockMethod method) {
180158
}
181159

182160
public VertexAiGeminiSafetySetting build() {
183-
return new VertexAiGeminiSafetySetting(this.category, this.threshold, this.method);
161+
return new VertexAiGeminiSafetySetting(this);
184162
}
185163

186164
}

0 commit comments

Comments
 (0)