Skip to content

Commit 3131daf

Browse files
committed
feat: add move dynamic generative providers
Azure Databricks Friendliai Google Mistral Nvidia Ollama OpenAI XAI
1 parent 478b7a6 commit 3131daf

10 files changed

Lines changed: 1343 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.weaviate.client6.v1.api.collections.generate;
2+
3+
import java.util.function.Function;
4+
5+
import io.weaviate.client6.v1.api.collections.generative.AnthropicGenerative;
6+
import io.weaviate.client6.v1.internal.ObjectBuilder;
7+
import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoGenerative;
8+
9+
public interface DynamicProvider {
10+
void appendTo(WeaviateProtoGenerative.GenerativeProvider.Builder req);
11+
12+
/**
13+
* Configure {@code generative-anthropic} as a dynamic provider.
14+
*
15+
* @param fn Lambda expression for optional parameters.
16+
*/
17+
public static DynamicProvider anthropic(
18+
Function<AnthropicGenerative.Provider.Builder, ObjectBuilder<AnthropicGenerative.Provider>> fn) {
19+
return AnthropicGenerative.Provider.of(fn);
20+
}
21+
}

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

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package io.weaviate.client6.v1.api.collections.generative;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
36
import java.util.function.Function;
47

58
import com.google.gson.annotations.SerializedName;
69

710
import io.weaviate.client6.v1.api.collections.Generative;
11+
import io.weaviate.client6.v1.api.collections.generate.DynamicProvider;
812
import 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;
915

1016
public record AzureOpenAiGenerative(
1117
@SerializedName("baseURL") String baseUrl,
@@ -107,4 +113,208 @@ public AzureOpenAiGenerative build() {
107113
return new AzureOpenAiGenerative(this);
108114
}
109115
}
116+
117+
public static record Provider(
118+
String baseUrl,
119+
Integer maxTokens,
120+
String model,
121+
Float temperature,
122+
Integer n,
123+
Float topP,
124+
Float frequencyPenalty,
125+
Float presencePenalty,
126+
String apiVersion,
127+
String resourceName,
128+
String deploymentId,
129+
List<String> stopSequences,
130+
List<String> images,
131+
List<String> imageProperties) implements DynamicProvider {
132+
133+
public static Provider of(
134+
Function<AzureOpenAiGenerative.Provider.Builder, ObjectBuilder<AzureOpenAiGenerative.Provider>> fn) {
135+
return fn.apply(new Builder()).build();
136+
}
137+
138+
@Override
139+
public void appendTo(
140+
io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoGenerative.GenerativeProvider.Builder req) {
141+
var provider = WeaviateProtoGenerative.GenerativeOpenAI.newBuilder();
142+
if (baseUrl != null) {
143+
provider.setBaseUrl(baseUrl);
144+
}
145+
if (maxTokens != null) {
146+
provider.setMaxTokens(maxTokens);
147+
}
148+
if (model != null) {
149+
provider.setModel(model);
150+
}
151+
if (temperature != null) {
152+
provider.setTemperature(temperature);
153+
}
154+
if (n != null) {
155+
provider.setN(n);
156+
}
157+
if (topP != null) {
158+
provider.setTopP(topP);
159+
}
160+
if (frequencyPenalty != null) {
161+
provider.setFrequencyPenalty(frequencyPenalty);
162+
}
163+
if (presencePenalty != null) {
164+
provider.setPresencePenalty(presencePenalty);
165+
}
166+
if (apiVersion != null) {
167+
provider.setApiVersion(apiVersion);
168+
}
169+
if (resourceName != null) {
170+
provider.setResourceName(resourceName);
171+
}
172+
if (deploymentId != null) {
173+
provider.setDeploymentId(deploymentId);
174+
}
175+
if (stopSequences != null) {
176+
provider.setStop(WeaviateProtoBase.TextArray.newBuilder()
177+
.addAllValues(stopSequences));
178+
}
179+
provider.setIsAzure(true);
180+
req.setOpenai(provider);
181+
}
182+
183+
public Provider(Builder builder) {
184+
this(
185+
builder.baseUrl,
186+
builder.maxTokens,
187+
builder.model,
188+
builder.temperature,
189+
builder.n,
190+
builder.topP,
191+
builder.frequencyPenalty,
192+
builder.presencePenalty,
193+
builder.apiVersion,
194+
builder.resourceName,
195+
builder.deploymentId,
196+
builder.stopSequences,
197+
builder.images,
198+
builder.imageProperties);
199+
}
200+
201+
public static class Builder implements ObjectBuilder<AzureOpenAiGenerative.Provider> {
202+
private String baseUrl;
203+
private Integer n;
204+
private Float topP;
205+
private String model;
206+
private Integer maxTokens;
207+
private Float temperature;
208+
private Float frequencyPenalty;
209+
private Float presencePenalty;
210+
private String apiVersion;
211+
private String resourceName;
212+
private String deploymentId;
213+
private final List<String> stopSequences = new ArrayList<>();
214+
private final List<String> images = new ArrayList<>();
215+
private final List<String> imageProperties = new ArrayList<>();
216+
217+
/** Base URL of the generative provider. */
218+
public Builder baseUrl(String baseUrl) {
219+
this.baseUrl = baseUrl;
220+
return this;
221+
}
222+
223+
public Builder n(int n) {
224+
this.n = n;
225+
return this;
226+
}
227+
228+
/** Top P value for nucleus sampling. */
229+
public Builder topP(float topP) {
230+
this.topP = topP;
231+
return this;
232+
}
233+
234+
public Builder frequencyPenalty(float frequencyPenalty) {
235+
this.frequencyPenalty = frequencyPenalty;
236+
return this;
237+
}
238+
239+
/** Top P value for nucleus sampling. */
240+
public Builder presencePenalty(float presencePenalty) {
241+
this.presencePenalty = presencePenalty;
242+
return this;
243+
}
244+
245+
/** Select generative model. */
246+
public Builder model(String model) {
247+
this.model = model;
248+
return this;
249+
}
250+
251+
/** Limit the number of tokens to generate in the response. */
252+
public Builder maxTokens(int maxTokens) {
253+
this.maxTokens = maxTokens;
254+
return this;
255+
}
256+
257+
/**
258+
* Set tokens which should signal the model to stop generating further output.
259+
*/
260+
public Builder stopSequences(String... stopSequences) {
261+
return stopSequences(Arrays.asList(stopSequences));
262+
}
263+
264+
/**
265+
* Set tokens which should signal the model to stop generating further output.
266+
*/
267+
public Builder stopSequences(List<String> stopSequences) {
268+
this.stopSequences.addAll(stopSequences);
269+
return this;
270+
}
271+
272+
public Builder apiVersion(String apiVersion) {
273+
this.apiVersion = apiVersion;
274+
return this;
275+
}
276+
277+
public Builder resourceName(String resourceName) {
278+
this.resourceName = resourceName;
279+
return this;
280+
}
281+
282+
public Builder deploymentId(String deploymentId) {
283+
this.deploymentId = deploymentId;
284+
return this;
285+
}
286+
287+
public Builder images(String... images) {
288+
return images(Arrays.asList(images));
289+
}
290+
291+
public Builder images(List<String> images) {
292+
this.images.addAll(images);
293+
return this;
294+
}
295+
296+
public Builder imageProperties(String... imageProperties) {
297+
return imageProperties(Arrays.asList(imageProperties));
298+
}
299+
300+
public Builder imageProperties(List<String> imageProperties) {
301+
this.imageProperties.addAll(imageProperties);
302+
return this;
303+
}
304+
305+
/**
306+
* Control the randomness of the model's output.
307+
* Higher values make output more random.
308+
*/
309+
public Builder temperature(float temperature) {
310+
this.temperature = temperature;
311+
return this;
312+
}
313+
314+
@Override
315+
public AzureOpenAiGenerative.Provider build() {
316+
return new AzureOpenAiGenerative.Provider(this);
317+
}
318+
}
319+
}
110320
}

0 commit comments

Comments
 (0)