Skip to content

Commit d59a7c2

Browse files
committed
feat: add generative modules
- Anthropic - AWS - Azure / OpenAI - Friendliai - Google - Nvidia - Ollama - Xai
1 parent f8f7bdf commit d59a7c2

14 files changed

Lines changed: 877 additions & 31 deletions

src/main/java/io/weaviate/client6/v1/api/collections/Generative.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,38 @@
1313
import com.google.gson.stream.JsonToken;
1414
import com.google.gson.stream.JsonWriter;
1515

16+
import io.weaviate.client6.v1.api.collections.generative.AnthropicGenerative;
1617
import io.weaviate.client6.v1.api.collections.generative.AnyscaleGenerative;
18+
import io.weaviate.client6.v1.api.collections.generative.AwsGenerative;
19+
import io.weaviate.client6.v1.api.collections.generative.AzureOpenAiGenerative;
1720
import io.weaviate.client6.v1.api.collections.generative.CohereGenerative;
1821
import io.weaviate.client6.v1.api.collections.generative.DatabricksGenerative;
1922
import io.weaviate.client6.v1.api.collections.generative.DummyGenerative;
23+
import io.weaviate.client6.v1.api.collections.generative.FriendliaiGenerative;
24+
import io.weaviate.client6.v1.api.collections.generative.GoogleGenerative;
2025
import io.weaviate.client6.v1.api.collections.generative.MistralGenerative;
26+
import io.weaviate.client6.v1.api.collections.generative.NvidiaGenerative;
27+
import io.weaviate.client6.v1.api.collections.generative.OllamaGenerative;
28+
import io.weaviate.client6.v1.api.collections.generative.OpenAiGenerative;
29+
import io.weaviate.client6.v1.api.collections.generative.XaiGenerative;
2130
import io.weaviate.client6.v1.internal.ObjectBuilder;
2231
import io.weaviate.client6.v1.internal.json.JsonEnum;
2332

2433
public interface Generative {
2534
public enum Kind implements JsonEnum<Kind> {
2635
ANYSCALE("generative-anyscale"),
36+
AWS("generative-aws"),
37+
ANTHROPIC("generative-anthropic"),
2738
COHERE("generative-cohere"),
2839
DATABRICKS("generative-databricks"),
40+
FRIENDLIAI("generative-friendliai"),
41+
GOOGLE("generative-google"),
2942
MISTRAL("generative-mistral"),
43+
NVIDIA("generative-nvidia"),
44+
OLLAMA("generative-ollama"),
45+
OPENAI("generative-openai"),
46+
AZURE_OPENAI("generative-openai"),
47+
XAI("generative-xai"),
3048
DUMMY("generative-dummy");
3149

3250
private static final Map<String, Kind> jsonValueMap = JsonEnum.collectNames(Kind.values());
@@ -76,9 +94,18 @@ private final void addAdapter(Gson gson, Generative.Kind kind, Class<? extends G
7694

7795
private final void init(Gson gson) {
7896
addAdapter(gson, Generative.Kind.ANYSCALE, AnyscaleGenerative.class);
97+
addAdapter(gson, Generative.Kind.ANTHROPIC, AnthropicGenerative.class);
98+
addAdapter(gson, Generative.Kind.AWS, AwsGenerative.class);
7999
addAdapter(gson, Generative.Kind.COHERE, CohereGenerative.class);
80100
addAdapter(gson, Generative.Kind.DATABRICKS, DatabricksGenerative.class);
101+
addAdapter(gson, Generative.Kind.GOOGLE, GoogleGenerative.class);
102+
addAdapter(gson, Generative.Kind.FRIENDLIAI, FriendliaiGenerative.class);
81103
addAdapter(gson, Generative.Kind.MISTRAL, MistralGenerative.class);
104+
addAdapter(gson, Generative.Kind.NVIDIA, NvidiaGenerative.class);
105+
addAdapter(gson, Generative.Kind.OLLAMA, OllamaGenerative.class);
106+
addAdapter(gson, Generative.Kind.OPENAI, OpenAiGenerative.class);
107+
addAdapter(gson, Generative.Kind.AZURE_OPENAI, AzureOpenAiGenerative.class);
108+
addAdapter(gson, Generative.Kind.XAI, XaiGenerative.class);
82109
addAdapter(gson, Generative.Kind.DUMMY, DummyGenerative.class);
83110
}
84111

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package io.weaviate.client6.v1.api.collections.generative;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.function.Function;
7+
8+
import com.google.gson.annotations.SerializedName;
9+
10+
import io.weaviate.client6.v1.api.collections.Generative;
11+
import io.weaviate.client6.v1.internal.ObjectBuilder;
12+
13+
public record AnthropicGenerative(
14+
@SerializedName("model") String model,
15+
@SerializedName("maxTokens") Integer maxTokens,
16+
@SerializedName("temperature") Float temperature,
17+
@SerializedName("topK") Integer topK,
18+
@SerializedName("stopSequences") List<String> stopSequences) implements Generative {
19+
20+
@Override
21+
public Kind _kind() {
22+
return Generative.Kind.ANTHROPIC;
23+
}
24+
25+
@Override
26+
public Object _self() {
27+
return this;
28+
}
29+
30+
public static AnthropicGenerative of() {
31+
return of(ObjectBuilder.identity());
32+
}
33+
34+
public static AnthropicGenerative of(Function<Builder, ObjectBuilder<AnthropicGenerative>> fn) {
35+
return fn.apply(new Builder()).build();
36+
}
37+
38+
public AnthropicGenerative(Builder builder) {
39+
this(
40+
builder.model,
41+
builder.maxTokens,
42+
builder.temperature,
43+
builder.topK,
44+
builder.stopSequences);
45+
}
46+
47+
public static class Builder implements ObjectBuilder<AnthropicGenerative> {
48+
private Integer topK;
49+
private String model;
50+
private Integer maxTokens;
51+
private Float temperature;
52+
private List<String> stopSequences = new ArrayList<>();
53+
54+
public Builder topK(int topK) {
55+
this.topK = topK;
56+
return this;
57+
}
58+
59+
/** Select generative model. */
60+
public Builder model(String model) {
61+
this.model = model;
62+
return this;
63+
}
64+
65+
/** Limit the number of tokens to generate in the response. */
66+
public Builder maxTokens(int maxTokens) {
67+
this.maxTokens = maxTokens;
68+
return this;
69+
}
70+
71+
public Builder stopSequences(String... stopSequences) {
72+
return stopSequences(Arrays.asList(stopSequences));
73+
}
74+
75+
public Builder stopSequences(List<String> stopSequences) {
76+
this.stopSequences = stopSequences;
77+
return this;
78+
}
79+
80+
/**
81+
* Control the randomness of the model's output.
82+
* Higher values make output more random.
83+
*/
84+
public Builder temperature(float temperature) {
85+
this.temperature = temperature;
86+
return this;
87+
}
88+
89+
@Override
90+
public AnthropicGenerative build() {
91+
return new AnthropicGenerative(this);
92+
}
93+
}
94+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public Builder model(String model) {
5252
return this;
5353
}
5454

55+
/**
56+
* Control the randomness of the model's output.
57+
* Higher values make output more random.
58+
*/
5559
public Builder temperature(float temperature) {
5660
this.temperature = temperature;
5761
return this;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package io.weaviate.client6.v1.api.collections.generative;
2+
3+
import java.util.function.Function;
4+
5+
import com.google.gson.annotations.SerializedName;
6+
7+
import io.weaviate.client6.v1.api.collections.Generative;
8+
import io.weaviate.client6.v1.internal.ObjectBuilder;
9+
10+
public record AwsGenerative(
11+
@SerializedName("region") String region,
12+
@SerializedName("service") String service,
13+
@SerializedName("endpoint") String baseURL,
14+
@SerializedName("model") String model) implements Generative {
15+
16+
@Override
17+
public Kind _kind() {
18+
return Generative.Kind.AWS;
19+
}
20+
21+
@Override
22+
public Object _self() {
23+
return this;
24+
}
25+
26+
public static AwsGenerative of(String region, String service) {
27+
return of(region, service, ObjectBuilder.identity());
28+
}
29+
30+
public static AwsGenerative of(String region, String service, Function<Builder, ObjectBuilder<AwsGenerative>> fn) {
31+
return fn.apply(new Builder(region, service)).build();
32+
}
33+
34+
public AwsGenerative(Builder builder) {
35+
this(
36+
builder.service,
37+
builder.region,
38+
builder.baseUrl,
39+
builder.model);
40+
}
41+
42+
public static class Builder implements ObjectBuilder<AwsGenerative> {
43+
private final String region;
44+
private final String service;
45+
46+
public Builder(String service, String region) {
47+
this.service = service;
48+
this.region = region;
49+
}
50+
51+
private String baseUrl;
52+
private String model;
53+
54+
/** Base URL of the generative provider. */
55+
public Builder baseUrl(String baseUrl) {
56+
this.baseUrl = baseUrl;
57+
return this;
58+
}
59+
60+
/** Select generative model. */
61+
public Builder model(String model) {
62+
this.model = model;
63+
return this;
64+
}
65+
66+
@Override
67+
public AwsGenerative build() {
68+
return new AwsGenerative(this);
69+
}
70+
}
71+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package io.weaviate.client6.v1.api.collections.generative;
2+
3+
import java.util.function.Function;
4+
5+
import com.google.gson.annotations.SerializedName;
6+
7+
import io.weaviate.client6.v1.api.collections.Generative;
8+
import io.weaviate.client6.v1.internal.ObjectBuilder;
9+
10+
public record AzureOpenAiGenerative(
11+
@SerializedName("baseURL") String baseUrl,
12+
@SerializedName("frequencyPenaltyProperty") Float frequencyPenalty,
13+
@SerializedName("presencePenaltyProperty") Float presencePenalty,
14+
@SerializedName("maxTokensProperty") Integer maxTokens,
15+
@SerializedName("temperatureProperty") Float temperature,
16+
@SerializedName("topPProperty") Float topP,
17+
18+
@SerializedName("resourceName") String resourceName,
19+
@SerializedName("deploymentId") String deploymentId) implements Generative {
20+
21+
@Override
22+
public Kind _kind() {
23+
return Generative.Kind.AZURE_OPENAI;
24+
}
25+
26+
@Override
27+
public Object _self() {
28+
return this;
29+
}
30+
31+
public static AzureOpenAiGenerative of(String resourceName, String deploymentId) {
32+
return of(resourceName, deploymentId, ObjectBuilder.identity());
33+
}
34+
35+
public static AzureOpenAiGenerative of(String resourceName, String deploymentId,
36+
Function<Builder, ObjectBuilder<AzureOpenAiGenerative>> fn) {
37+
return fn.apply(new Builder(resourceName, deploymentId)).build();
38+
}
39+
40+
public AzureOpenAiGenerative(Builder builder) {
41+
this(
42+
builder.baseUrl,
43+
builder.frequencyPenalty,
44+
builder.presencePenalty,
45+
builder.maxTokens,
46+
builder.temperature,
47+
builder.topP,
48+
builder.resourceName,
49+
builder.deploymentId);
50+
}
51+
52+
public static class Builder implements ObjectBuilder<AzureOpenAiGenerative> {
53+
private final String resourceName;
54+
private final String deploymentId;
55+
56+
private String baseUrl;
57+
private Float frequencyPenalty;
58+
private Float presencePenalty;
59+
private Integer maxTokens;
60+
private Float temperature;
61+
private Float topP;
62+
63+
public Builder(String resourceName, String deploymentId) {
64+
this.resourceName = resourceName;
65+
this.deploymentId = deploymentId;
66+
}
67+
68+
/** Base URL of the generative provider. */
69+
public Builder baseUrl(String baseUrl) {
70+
this.baseUrl = baseUrl;
71+
return this;
72+
}
73+
74+
/** Limit the number of tokens to generate in the response. */
75+
public Builder maxTokens(int maxTokens) {
76+
this.maxTokens = maxTokens;
77+
return this;
78+
}
79+
80+
/**
81+
* Control the randomness of the model's output.
82+
* Higher values make output more random.
83+
*/
84+
public Builder temperature(float temperature) {
85+
this.temperature = temperature;
86+
return this;
87+
}
88+
89+
public Builder frequencyPenalty(float frequencyPenalty) {
90+
this.frequencyPenalty = frequencyPenalty;
91+
return this;
92+
}
93+
94+
public Builder presencePenalty(float presencePenalty) {
95+
this.presencePenalty = presencePenalty;
96+
return this;
97+
}
98+
99+
/** Top P value for nucleus sampling. */
100+
public Builder topP(float topP) {
101+
this.topP = topP;
102+
return this;
103+
}
104+
105+
@Override
106+
public AzureOpenAiGenerative build() {
107+
return new AzureOpenAiGenerative(this);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)