88import com .google .gson .annotations .SerializedName ;
99
1010import io .weaviate .client6 .v1 .api .collections .Generative ;
11+ import io .weaviate .client6 .v1 .api .collections .generate .DynamicProvider ;
1112import io .weaviate .client6 .v1 .internal .ObjectBuilder ;
13+ import io .weaviate .client6 .v1 .internal .grpc .protocol .WeaviateProtoBase ;
14+ import io .weaviate .client6 .v1 .internal .grpc .protocol .WeaviateProtoGenerative ;
1215
1316public record AnthropicGenerative (
1417 @ SerializedName ("model" ) String model ,
1518 @ SerializedName ("maxTokens" ) Integer maxTokens ,
1619 @ SerializedName ("temperature" ) Float temperature ,
1720 @ SerializedName ("topK" ) Integer topK ,
21+ @ SerializedName ("topP" ) Float topP ,
1822 @ SerializedName ("stopSequences" ) List <String > stopSequences ) implements Generative {
1923
2024 @ Override
@@ -41,21 +45,30 @@ public AnthropicGenerative(Builder builder) {
4145 builder .maxTokens ,
4246 builder .temperature ,
4347 builder .topK ,
48+ builder .topP ,
4449 builder .stopSequences );
4550 }
4651
4752 public static class Builder implements ObjectBuilder <AnthropicGenerative > {
4853 private Integer topK ;
54+ private Float topP ;
4955 private String model ;
5056 private Integer maxTokens ;
5157 private Float temperature ;
52- private List <String > stopSequences = new ArrayList <>();
58+ private final List <String > stopSequences = new ArrayList <>();
5359
60+ /** Top K value for sampling. */
5461 public Builder topK (int topK ) {
5562 this .topK = topK ;
5663 return this ;
5764 }
5865
66+ /** Top P value for nucleus sampling. */
67+ public Builder topP (float topP ) {
68+ this .topP = topP ;
69+ return this ;
70+ }
71+
5972 /** Select generative model. */
6073 public Builder model (String model ) {
6174 this .model = model ;
@@ -68,12 +81,18 @@ public Builder maxTokens(int maxTokens) {
6881 return this ;
6982 }
7083
84+ /**
85+ * Set tokens which should signal the model to stop generating further output.
86+ */
7187 public Builder stopSequences (String ... stopSequences ) {
7288 return stopSequences (Arrays .asList (stopSequences ));
7389 }
7490
91+ /**
92+ * Set tokens which should signal the model to stop generating further output.
93+ */
7594 public Builder stopSequences (List <String > stopSequences ) {
76- this .stopSequences = stopSequences ;
95+ this .stopSequences . addAll ( stopSequences ) ;
7796 return this ;
7897 }
7998
@@ -102,4 +121,161 @@ public Generative.Kind _kind() {
102121 public static record Usage (Long inputTokens , Long outputTokens ) {
103122 }
104123 }
124+
125+ public static record Provider (
126+ String baseUrl ,
127+ Integer maxTokens ,
128+ String model ,
129+ Float temperature ,
130+ Integer topK ,
131+ Float topP ,
132+ List <String > stopSequences ,
133+ List <String > images ,
134+ List <String > imageProperties ) implements DynamicProvider {
135+
136+ public static Provider of (
137+ Function <AnthropicGenerative .Provider .Builder , ObjectBuilder <AnthropicGenerative .Provider >> fn ) {
138+ return fn .apply (new Builder ()).build ();
139+ }
140+
141+ @ Override
142+ public void appendTo (
143+ io .weaviate .client6 .v1 .internal .grpc .protocol .WeaviateProtoGenerative .GenerativeProvider .Builder req ) {
144+ var provider = WeaviateProtoGenerative .GenerativeAnthropic .newBuilder ();
145+ if (baseUrl != null ) {
146+ provider .setBaseUrl (baseUrl );
147+ }
148+ if (maxTokens != null ) {
149+ provider .setMaxTokens (maxTokens );
150+ }
151+ if (model != null ) {
152+ provider .setModel (model );
153+ }
154+ if (temperature != null ) {
155+ provider .setTemperature (temperature );
156+ }
157+ if (topK != null ) {
158+ provider .setTopK (topK );
159+ }
160+ if (topP != null ) {
161+ provider .setTopP (topP );
162+ }
163+
164+ if (stopSequences != null ) {
165+ provider .setStopSequences (WeaviateProtoBase .TextArray .newBuilder ()
166+ .addAllValues (stopSequences ));
167+ }
168+ if (images != null ) {
169+ provider .setImages (WeaviateProtoBase .TextArray .newBuilder ()
170+ .addAllValues (images ));
171+ }
172+ if (imageProperties != null ) {
173+ provider .setImageProperties (WeaviateProtoBase .TextArray .newBuilder ()
174+ .addAllValues (imageProperties ));
175+ }
176+ req .setAnthropic (provider );
177+ }
178+
179+ public Provider (Builder builder ) {
180+ this (
181+ builder .baseUrl ,
182+ builder .maxTokens ,
183+ builder .model ,
184+ builder .temperature ,
185+ builder .topK ,
186+ builder .topP ,
187+ builder .stopSequences ,
188+ builder .images ,
189+ builder .imageProperties );
190+ }
191+
192+ public static class Builder implements ObjectBuilder <AnthropicGenerative .Provider > {
193+ private String baseUrl ;
194+ private Integer topK ;
195+ private Float topP ;
196+ private String model ;
197+ private Integer maxTokens ;
198+ private Float temperature ;
199+ private final List <String > stopSequences = new ArrayList <>();
200+ private final List <String > images = new ArrayList <>();
201+ private final List <String > imageProperties = new ArrayList <>();
202+
203+ /** Base URL of the generative provider. */
204+ public Builder baseUrl (String baseUrl ) {
205+ this .baseUrl = baseUrl ;
206+ return this ;
207+ }
208+
209+ /** Top K value for sampling. */
210+ public Builder topK (int topK ) {
211+ this .topK = topK ;
212+ return this ;
213+ }
214+
215+ /** Top P value for nucleus sampling. */
216+ public Builder topP (float topP ) {
217+ this .topP = topP ;
218+ return this ;
219+ }
220+
221+ /** Select generative model. */
222+ public Builder model (String model ) {
223+ this .model = model ;
224+ return this ;
225+ }
226+
227+ /** Limit the number of tokens to generate in the response. */
228+ public Builder maxTokens (int maxTokens ) {
229+ this .maxTokens = maxTokens ;
230+ return this ;
231+ }
232+
233+ /**
234+ * Set tokens which should signal the model to stop generating further output.
235+ */
236+ public Builder stopSequences (String ... stopSequences ) {
237+ return stopSequences (Arrays .asList (stopSequences ));
238+ }
239+
240+ /**
241+ * Set tokens which should signal the model to stop generating further output.
242+ */
243+ public Builder stopSequences (List <String > stopSequences ) {
244+ this .stopSequences .addAll (stopSequences );
245+ return this ;
246+ }
247+
248+ public Builder images (String ... images ) {
249+ return images (Arrays .asList (images ));
250+ }
251+
252+ public Builder images (List <String > images ) {
253+ this .images .addAll (images );
254+ return this ;
255+ }
256+
257+ public Builder imageProperties (String ... imageProperties ) {
258+ return imageProperties (Arrays .asList (imageProperties ));
259+ }
260+
261+ public Builder imageProperties (List <String > imageProperties ) {
262+ this .imageProperties .addAll (imageProperties );
263+ return this ;
264+ }
265+
266+ /**
267+ * Control the randomness of the model's output.
268+ * Higher values make output more random.
269+ */
270+ public Builder temperature (float temperature ) {
271+ this .temperature = temperature ;
272+ return this ;
273+ }
274+
275+ @ Override
276+ public AnthropicGenerative .Provider build () {
277+ return new AnthropicGenerative .Provider (this );
278+ }
279+ }
280+ }
105281}
0 commit comments