Skip to content

Commit 1f522f1

Browse files
committed
Refactor stopSequences initialization in generative classes
1 parent f3e7a5a commit 1f522f1

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/generative/AnthropicGenerative.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static class Builder implements ObjectBuilder<AnthropicGenerative> {
5858
private Integer maxTokens;
5959
private Float temperature;
6060
private String baseUrl;
61-
private final List<String> stopSequences = new ArrayList<>();
61+
private List<String> stopSequences;
6262

6363
/** Base URL of the generative provider. */
6464
public Builder baseUrl(String baseUrl) {
@@ -101,6 +101,9 @@ public Builder stopSequences(String... stopSequences) {
101101
* Set tokens which should signal the model to stop generating further output.
102102
*/
103103
public Builder stopSequences(List<String> stopSequences) {
104+
if (this.stopSequences == null) {
105+
this.stopSequences = new ArrayList<>();
106+
}
104107
this.stopSequences.addAll(stopSequences);
105108
return this;
106109
}
@@ -199,9 +202,9 @@ public static class Builder implements ObjectBuilder<AnthropicGenerative.Provide
199202
private String model;
200203
private Integer maxTokens;
201204
private Float temperature;
202-
private final List<String> stopSequences = new ArrayList<>();
203-
private final List<String> images = new ArrayList<>();
204-
private final List<String> imageProperties = new ArrayList<>();
205+
private List<String> stopSequences;
206+
private List<String> images;
207+
private List<String> imageProperties;
205208

206209
/** Base URL of the generative provider. */
207210
public Builder baseUrl(String baseUrl) {
@@ -244,6 +247,9 @@ public Builder stopSequences(String... stopSequences) {
244247
* Set tokens which should signal the model to stop generating further output.
245248
*/
246249
public Builder stopSequences(List<String> stopSequences) {
250+
if (this.stopSequences == null) {
251+
this.stopSequences = new ArrayList<>();
252+
}
247253
this.stopSequences.addAll(stopSequences);
248254
return this;
249255
}
@@ -253,6 +259,9 @@ public Builder images(String... images) {
253259
}
254260

255261
public Builder images(List<String> images) {
262+
if (this.images == null) {
263+
this.images = new ArrayList<>();
264+
}
256265
this.images.addAll(images);
257266
return this;
258267
}
@@ -262,6 +271,9 @@ public Builder imageProperties(String... imageProperties) {
262271
}
263272

264273
public Builder imageProperties(List<String> imageProperties) {
274+
if (this.imageProperties == null) {
275+
this.imageProperties = new ArrayList<>();
276+
}
265277
this.imageProperties.addAll(imageProperties);
266278
return this;
267279
}

src/main/java/io/weaviate/client6/v1/api/collections/generative/AwsGenerative.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Builder(Service service, String region) {
9090
private Integer maxTokensToSample;
9191
private Float topP;
9292
private Integer topK;
93-
private final List<String> stopSequences = new ArrayList<>();
93+
private List<String> stopSequences;
9494

9595
/** Base URL of the generative provider. */
9696
protected Builder endpoint(String endpoint) {
@@ -153,6 +153,9 @@ public Builder stopSequences(String... stopSequences) {
153153

154154
/** Stop sequences for the model. */
155155
public Builder stopSequences(List<String> stopSequences) {
156+
if (this.stopSequences == null) {
157+
this.stopSequences = new ArrayList<>();
158+
}
156159
this.stopSequences.addAll(stopSequences);
157160
return this;
158161
}

src/main/java/io/weaviate/client6/v1/api/collections/generative/CohereGenerative.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static class Builder implements ObjectBuilder<CohereGenerative> {
5858
private Integer maxTokens;
5959
private Float temperature;
6060
private String returnLikelihoodsProperty;
61-
private List<String> stopSequences = new ArrayList<>();
61+
private List<String> stopSequences;
6262

6363
/** Base URL of the generative provider. */
6464
public Builder baseUrl(String baseUrl) {
@@ -100,7 +100,10 @@ public Builder stopSequences(String... stopSequences) {
100100
* Set tokens which should signal the model to stop generating further output.
101101
*/
102102
public Builder stopSequences(List<String> stopSequences) {
103-
this.stopSequences = stopSequences;
103+
if (this.stopSequences == null) {
104+
this.stopSequences = new ArrayList<>();
105+
}
106+
this.stopSequences.addAll(stopSequences);
104107
return this;
105108
}
106109

@@ -208,7 +211,7 @@ public static class Builder implements ObjectBuilder<CohereGenerative.Provider>
208211
private Float temperature;
209212
private Float frequencyPenalty;
210213
private Float presencePenalty;
211-
private final List<String> stopSequences = new ArrayList<>();
214+
private List<String> stopSequences;
212215

213216
/** Base URL of the generative provider. */
214217
public Builder baseUrl(String baseUrl) {
@@ -262,6 +265,9 @@ public Builder stopSequences(String... stopSequences) {
262265
* Set tokens which should signal the model to stop generating further output.
263266
*/
264267
public Builder stopSequences(List<String> stopSequences) {
268+
if (this.stopSequences == null) {
269+
this.stopSequences = new ArrayList<>();
270+
}
265271
this.stopSequences.addAll(stopSequences);
266272
return this;
267273
}

0 commit comments

Comments
 (0)