|
| 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.api.collections.generate.GenerativeProvider; |
| 12 | +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; |
| 15 | + |
| 16 | +public record DeepseekGenerative( |
| 17 | + @SerializedName("baseURL") String baseUrl, |
| 18 | + @SerializedName("model") String model, |
| 19 | + @SerializedName("maxTokens") Integer maxTokens, |
| 20 | + @SerializedName("temperature") Float temperature, |
| 21 | + @SerializedName("frequencyPenalty") Float frequencyPenalty, |
| 22 | + @SerializedName("presencePenalty") Float presencePenalty, |
| 23 | + @SerializedName("topP") Float topP, |
| 24 | + @SerializedName("stop") List<String> stopSequences) implements Generative { |
| 25 | + |
| 26 | + @Override |
| 27 | + public Generative.Kind _kind() { |
| 28 | + return Generative.Kind.DATABRICKS; |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public Object _self() { |
| 33 | + return this; |
| 34 | + } |
| 35 | + |
| 36 | + public static DeepseekGenerative of() { |
| 37 | + return of(ObjectBuilder.identity()); |
| 38 | + } |
| 39 | + |
| 40 | + public static DeepseekGenerative of(Function<Builder, ObjectBuilder<DeepseekGenerative>> fn) { |
| 41 | + return fn.apply(new Builder()).build(); |
| 42 | + } |
| 43 | + |
| 44 | + public DeepseekGenerative(Builder builder) { |
| 45 | + this( |
| 46 | + builder.baseUrl, |
| 47 | + builder.model, |
| 48 | + builder.maxTokens, |
| 49 | + builder.temperature, |
| 50 | + builder.frequencyPenalty, |
| 51 | + builder.presencePenalty, |
| 52 | + builder.topP, |
| 53 | + builder.stopSequences); |
| 54 | + } |
| 55 | + |
| 56 | + public static class Builder implements ObjectBuilder<DeepseekGenerative> { |
| 57 | + private String baseUrl; |
| 58 | + private String model; |
| 59 | + private Float temperature; |
| 60 | + private Integer maxTokens; |
| 61 | + private Float frequencyPenalty; |
| 62 | + private Float presencePenalty; |
| 63 | + private Float topP; |
| 64 | + private List<String> stopSequences = new ArrayList<>(); |
| 65 | + |
| 66 | + /** Base URL of the generative provider. */ |
| 67 | + public Builder baseUrl(String baseUrl) { |
| 68 | + this.baseUrl = baseUrl; |
| 69 | + return this; |
| 70 | + } |
| 71 | + |
| 72 | + /** Limit the number of tokens to generate in the response. */ |
| 73 | + public Builder maxTokens(int maxTokens) { |
| 74 | + this.maxTokens = maxTokens; |
| 75 | + return this; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Control the randomness of the model's output. |
| 80 | + * Higher values make output more random. |
| 81 | + */ |
| 82 | + public Builder temperature(float temperature) { |
| 83 | + this.temperature = temperature; |
| 84 | + return this; |
| 85 | + } |
| 86 | + |
| 87 | + public Builder frequencyPenalty(float frequencyPenalty) { |
| 88 | + this.frequencyPenalty = frequencyPenalty; |
| 89 | + return this; |
| 90 | + } |
| 91 | + |
| 92 | + public Builder presencePenalty(float presencePenalty) { |
| 93 | + this.presencePenalty = presencePenalty; |
| 94 | + return this; |
| 95 | + } |
| 96 | + |
| 97 | + /** Top P value for nucleus sampling. */ |
| 98 | + public Builder topP(float topP) { |
| 99 | + this.topP = topP; |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + public Builder stopSequences(String... values) { |
| 104 | + return stopSequences(Arrays.asList(values)); |
| 105 | + } |
| 106 | + |
| 107 | + public Builder stopSequences(List<String> values) { |
| 108 | + this.stopSequences.addAll(values); |
| 109 | + return this; |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public DeepseekGenerative build() { |
| 114 | + return new DeepseekGenerative(this); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + public static record Metadata(ProviderMetadata.Usage usage) implements ProviderMetadata { |
| 119 | + } |
| 120 | + |
| 121 | + public static record Provider( |
| 122 | + String baseUrl, |
| 123 | + String model, |
| 124 | + Integer maxTokens, |
| 125 | + Float temperature, |
| 126 | + Float frequencyPenalty, |
| 127 | + Float presencePenalty, |
| 128 | + Float topP, |
| 129 | + List<String> stopSequences) implements GenerativeProvider { |
| 130 | + |
| 131 | + public static Provider of( |
| 132 | + Function<DeepseekGenerative.Provider.Builder, ObjectBuilder<DeepseekGenerative.Provider>> fn) { |
| 133 | + return fn.apply(new Builder()).build(); |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public void appendTo( |
| 138 | + io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoGenerative.GenerativeProvider.Builder req) { |
| 139 | + var provider = WeaviateProtoGenerative.GenerativeDeepseek.newBuilder(); |
| 140 | + if (baseUrl != null) { |
| 141 | + provider.setBaseUrl(baseUrl); |
| 142 | + } |
| 143 | + if (model != null) { |
| 144 | + provider.setModel(model); |
| 145 | + } |
| 146 | + if (temperature != null) { |
| 147 | + provider.setTemperature(temperature); |
| 148 | + } |
| 149 | + if (maxTokens != null) { |
| 150 | + provider.setMaxTokens(maxTokens); |
| 151 | + } |
| 152 | + if (topP != null) { |
| 153 | + provider.setTopP(topP); |
| 154 | + } |
| 155 | + if (frequencyPenalty != null) { |
| 156 | + provider.setFrequencyPenalty(frequencyPenalty); |
| 157 | + } |
| 158 | + if (presencePenalty != null) { |
| 159 | + provider.setPresencePenalty(presencePenalty); |
| 160 | + } |
| 161 | + if (stopSequences != null) { |
| 162 | + provider.setStop(WeaviateProtoBase.TextArray.newBuilder() |
| 163 | + .addAllValues(stopSequences)); |
| 164 | + } |
| 165 | + req.setDeepseek(provider); |
| 166 | + } |
| 167 | + |
| 168 | + public Provider(Builder builder) { |
| 169 | + this( |
| 170 | + builder.baseUrl, |
| 171 | + builder.model, |
| 172 | + builder.maxTokens, |
| 173 | + builder.temperature, |
| 174 | + builder.frequencyPenalty, |
| 175 | + builder.presencePenalty, |
| 176 | + builder.topP, |
| 177 | + builder.stopSequences); |
| 178 | + } |
| 179 | + |
| 180 | + public static class Builder implements ObjectBuilder<DeepseekGenerative.Provider> { |
| 181 | + private String baseUrl; |
| 182 | + private String model; |
| 183 | + private Float temperature; |
| 184 | + private Integer maxTokens; |
| 185 | + private Float frequencyPenalty; |
| 186 | + private Float presencePenalty; |
| 187 | + private Float topP; |
| 188 | + private List<String> stopSequences = new ArrayList<>(); |
| 189 | + |
| 190 | + /** Base URL of the generative provider. */ |
| 191 | + public Builder baseUrl(String baseUrl) { |
| 192 | + this.baseUrl = baseUrl; |
| 193 | + return this; |
| 194 | + } |
| 195 | + |
| 196 | + /** Limit the number of tokens to generate in the response. */ |
| 197 | + public Builder maxTokens(int maxTokens) { |
| 198 | + this.maxTokens = maxTokens; |
| 199 | + return this; |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Control the randomness of the model's output. |
| 204 | + * Higher values make output more random. |
| 205 | + */ |
| 206 | + public Builder temperature(float temperature) { |
| 207 | + this.temperature = temperature; |
| 208 | + return this; |
| 209 | + } |
| 210 | + |
| 211 | + public Builder frequencyPenalty(float frequencyPenalty) { |
| 212 | + this.frequencyPenalty = frequencyPenalty; |
| 213 | + return this; |
| 214 | + } |
| 215 | + |
| 216 | + public Builder presencePenalty(float presencePenalty) { |
| 217 | + this.presencePenalty = presencePenalty; |
| 218 | + return this; |
| 219 | + } |
| 220 | + |
| 221 | + /** Top P value for nucleus sampling. */ |
| 222 | + public Builder topP(float topP) { |
| 223 | + this.topP = topP; |
| 224 | + return this; |
| 225 | + } |
| 226 | + |
| 227 | + public Builder stop(String... values) { |
| 228 | + return stop(Arrays.asList(values)); |
| 229 | + } |
| 230 | + |
| 231 | + public Builder stop(List<String> values) { |
| 232 | + this.stopSequences.addAll(values); |
| 233 | + return this; |
| 234 | + } |
| 235 | + |
| 236 | + @Override |
| 237 | + public DeepseekGenerative.Provider build() { |
| 238 | + return new DeepseekGenerative.Provider(this); |
| 239 | + } |
| 240 | + } |
| 241 | + } |
| 242 | +} |
0 commit comments