|
28 | 28 | import io.weaviate.client6.v1.api.collections.generative.OpenAiGenerative; |
29 | 29 | import io.weaviate.client6.v1.api.collections.generative.XaiGenerative; |
30 | 30 | import io.weaviate.client6.v1.internal.ObjectBuilder; |
| 31 | +import io.weaviate.client6.v1.internal.TaggedUnion; |
31 | 32 | import io.weaviate.client6.v1.internal.json.JsonEnum; |
32 | 33 |
|
33 | | -public interface Generative { |
| 34 | +public interface Generative extends TaggedUnion<Generative.Kind, Object> { |
34 | 35 | public enum Kind implements JsonEnum<Kind> { |
35 | 36 | ANYSCALE("generative-anyscale"), |
36 | 37 | AWS("generative-aws"), |
@@ -64,10 +65,6 @@ public static Kind valueOfJson(String jsonValue) { |
64 | 65 | } |
65 | 66 | } |
66 | 67 |
|
67 | | - Kind _kind(); |
68 | | - |
69 | | - Object _self(); |
70 | | - |
71 | 68 | /** Configure a default {@code generative-anthropic} module. */ |
72 | 69 | public static Generative anthropic() { |
73 | 70 | return AnthropicGenerative.of(); |
@@ -277,6 +274,201 @@ public static Generative xai(Function<XaiGenerative.Builder, ObjectBuilder<XaiGe |
277 | 274 | return XaiGenerative.of(fn); |
278 | 275 | } |
279 | 276 |
|
| 277 | + /** Is this a {@code generative-anyscale} provider? */ |
| 278 | + default boolean isAnyscale() { |
| 279 | + return _is(Generative.Kind.ANYSCALE); |
| 280 | + } |
| 281 | + |
| 282 | + /** |
| 283 | + * Get as {@link AnyscaleGenerative} instance. |
| 284 | + * |
| 285 | + * @throws IllegalStateException if the current kind is not |
| 286 | + * {@code generative-anyscale}. |
| 287 | + */ |
| 288 | + default AnyscaleGenerative asAnyscale() { |
| 289 | + return _as(Generative.Kind.ANYSCALE); |
| 290 | + } |
| 291 | + |
| 292 | + /** Is this a {@code generative-aws} provider? */ |
| 293 | + default boolean isAws() { |
| 294 | + return _is(Generative.Kind.AWS); |
| 295 | + } |
| 296 | + |
| 297 | + /** |
| 298 | + * Get as {@link AwsGenerative} instance. |
| 299 | + * |
| 300 | + * @throws IllegalStateException if the current kind is not |
| 301 | + * {@code generative-aws}. |
| 302 | + */ |
| 303 | + default AwsGenerative asAws() { |
| 304 | + return _as(Generative.Kind.AWS); |
| 305 | + } |
| 306 | + |
| 307 | + /** Is this a {@code generative-anthropic} provider? */ |
| 308 | + default boolean isAnthropic() { |
| 309 | + return _is(Generative.Kind.ANTHROPIC); |
| 310 | + } |
| 311 | + |
| 312 | + /** |
| 313 | + * Get as {@link AnthropicGenerative} instance. |
| 314 | + * |
| 315 | + * @throws IllegalStateException if the current kind is not |
| 316 | + * {@code generative-anthropic}. |
| 317 | + */ |
| 318 | + default AnthropicGenerative asAnthropic() { |
| 319 | + return _as(Generative.Kind.ANTHROPIC); |
| 320 | + } |
| 321 | + |
| 322 | + /** Is this a {@code generative-cohere} provider? */ |
| 323 | + default boolean isCohere() { |
| 324 | + return _is(Generative.Kind.COHERE); |
| 325 | + } |
| 326 | + |
| 327 | + /** |
| 328 | + * Get as {@link CohereGenerative} instance. |
| 329 | + * |
| 330 | + * @throws IllegalStateException if the current kind is not |
| 331 | + * {@code generative-cohere}. |
| 332 | + */ |
| 333 | + default CohereGenerative asCohere() { |
| 334 | + return _as(Generative.Kind.COHERE); |
| 335 | + } |
| 336 | + |
| 337 | + /** Is this a {@code generative-databricks} provider? */ |
| 338 | + default boolean isDatabricks() { |
| 339 | + return _is(Generative.Kind.DATABRICKS); |
| 340 | + } |
| 341 | + |
| 342 | + /** |
| 343 | + * Get as {@link DatabricksGenerative} instance. |
| 344 | + * |
| 345 | + * @throws IllegalStateException if the current kind is not |
| 346 | + * {@code generative-databricks}. |
| 347 | + */ |
| 348 | + default DatabricksGenerative asDatabricks() { |
| 349 | + return _as(Generative.Kind.DATABRICKS); |
| 350 | + } |
| 351 | + |
| 352 | + /** Is this a {@code generative-friendliai} provider? */ |
| 353 | + default boolean isFriendliai() { |
| 354 | + return _is(Generative.Kind.FRIENDLIAI); |
| 355 | + } |
| 356 | + |
| 357 | + /** |
| 358 | + * Get as {@link FriendliaiGenerative} instance. |
| 359 | + * |
| 360 | + * @throws IllegalStateException if the current kind is not |
| 361 | + * {@code generative-friendliai}. |
| 362 | + */ |
| 363 | + default FriendliaiGenerative asFriendliai() { |
| 364 | + return _as(Generative.Kind.FRIENDLIAI); |
| 365 | + } |
| 366 | + |
| 367 | + /** Is this a {@code generative-palm} provider? */ |
| 368 | + default boolean isGoogle() { |
| 369 | + return _is(Generative.Kind.GOOGLE); |
| 370 | + } |
| 371 | + |
| 372 | + /** |
| 373 | + * Get as {@link GoogleGenerative} instance. |
| 374 | + * |
| 375 | + * @throws IllegalStateException if the current kind is not |
| 376 | + * {@code generative-palm}. |
| 377 | + */ |
| 378 | + default GoogleGenerative asGoogle() { |
| 379 | + return _as(Generative.Kind.GOOGLE); |
| 380 | + } |
| 381 | + |
| 382 | + /** Is this a {@code generative-mistral} provider? */ |
| 383 | + default boolean isMistral() { |
| 384 | + return _is(Generative.Kind.MISTRAL); |
| 385 | + } |
| 386 | + |
| 387 | + /** |
| 388 | + * Get as {@link MistralGenerative} instance. |
| 389 | + * |
| 390 | + * @throws IllegalStateException if the current kind is not |
| 391 | + * {@code generative-mistral}. |
| 392 | + */ |
| 393 | + default MistralGenerative asMistral() { |
| 394 | + return _as(Generative.Kind.MISTRAL); |
| 395 | + } |
| 396 | + |
| 397 | + /** Is this a {@code generative-nvidia} provider? */ |
| 398 | + default boolean isNvidia() { |
| 399 | + return _is(Generative.Kind.NVIDIA); |
| 400 | + } |
| 401 | + |
| 402 | + /** |
| 403 | + * Get as {@link NvidiaGenerative} instance. |
| 404 | + * |
| 405 | + * @throws IllegalStateException if the current kind is not |
| 406 | + * {@code generative-nvidia}. |
| 407 | + */ |
| 408 | + default NvidiaGenerative asNvidia() { |
| 409 | + return _as(Generative.Kind.NVIDIA); |
| 410 | + } |
| 411 | + |
| 412 | + /** Is this a {@code generative-ollama} provider? */ |
| 413 | + default boolean isOllama() { |
| 414 | + return _is(Generative.Kind.OLLAMA); |
| 415 | + } |
| 416 | + |
| 417 | + /** |
| 418 | + * Get as {@link OllamaGenerative} instance. |
| 419 | + * |
| 420 | + * @throws IllegalStateException if the current kind is not |
| 421 | + * {@code generative-ollama}. |
| 422 | + */ |
| 423 | + default OllamaGenerative asOllama() { |
| 424 | + return _as(Generative.Kind.OLLAMA); |
| 425 | + } |
| 426 | + |
| 427 | + /** Is this a {@code generative-openai} provider? */ |
| 428 | + default boolean isOpenAi() { |
| 429 | + return _is(Generative.Kind.OPENAI); |
| 430 | + } |
| 431 | + |
| 432 | + /** |
| 433 | + * Get as {@link OpenAiGenerative} instance. |
| 434 | + * |
| 435 | + * @throws IllegalStateException if the current kind is not |
| 436 | + * {@code generative-openai}. |
| 437 | + */ |
| 438 | + default OpenAiGenerative asOpenAi() { |
| 439 | + return _as(Generative.Kind.OPENAI); |
| 440 | + } |
| 441 | + |
| 442 | + /** Is this an Azure-specific {@code generative-openai} provider? */ |
| 443 | + default boolean isAzure() { |
| 444 | + return _is(Generative.Kind.AZURE_OPENAI); |
| 445 | + } |
| 446 | + |
| 447 | + /** |
| 448 | + * Get as {@link AzureOpenAiGenerative} instance. |
| 449 | + * |
| 450 | + * @throws IllegalStateException if the current kind is not |
| 451 | + * {@code generative-openai}. |
| 452 | + */ |
| 453 | + default AzureOpenAiGenerative asAzure() { |
| 454 | + return _as(Generative.Kind.AZURE_OPENAI); |
| 455 | + } |
| 456 | + |
| 457 | + /** Is this a {@code generative-xai} provider? */ |
| 458 | + default boolean isXai() { |
| 459 | + return _is(Generative.Kind.XAI); |
| 460 | + } |
| 461 | + |
| 462 | + /** |
| 463 | + * Get as {@link XaiGenerative} instance. |
| 464 | + * |
| 465 | + * @throws IllegalStateException if the current kind is not |
| 466 | + * {@code generative-xai}. |
| 467 | + */ |
| 468 | + default XaiGenerative asXai() { |
| 469 | + return _as(Generative.Kind.XAI); |
| 470 | + } |
| 471 | + |
280 | 472 | public static enum CustomTypeAdapterFactory implements TypeAdapterFactory { |
281 | 473 | INSTANCE; |
282 | 474 |
|
@@ -316,14 +508,15 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { |
316 | 508 | init(gson); |
317 | 509 | } |
318 | 510 |
|
319 | | - final TypeAdapter<T> writeAdapter = (TypeAdapter<T>) gson.getDelegateAdapter(this, TypeToken.get(rawType)); |
| 511 | + final TypeAdapter<Generative> writeAdapter = (TypeAdapter<Generative>) gson.getDelegateAdapter(this, |
| 512 | + TypeToken.get(rawType)); |
320 | 513 | return (TypeAdapter<T>) new TypeAdapter<Generative>() { |
321 | 514 |
|
322 | 515 | @Override |
323 | 516 | public void write(JsonWriter out, Generative value) throws IOException { |
324 | 517 | out.beginObject(); |
325 | 518 | out.name(value._kind().jsonValue()); |
326 | | - writeAdapter.write(out, (T) value._self()); |
| 519 | + writeAdapter.write(out, value._self()); |
327 | 520 | out.endObject(); |
328 | 521 | } |
329 | 522 |
|
|
0 commit comments