001/* 002 * Copyright (c) 2026, Oracle and/or its affiliates. 003 * 004 * Licensed under the Universal Permissive License Version 1.0 as shown at 005 * https://oss.oracle.com/licenses/upl/ 006 */ 007package com.oracle.database.selectai.model; 008 009/** 010 * Convenience object for applying provider-specific attributes to 011 * {@link ProfileAttributes.Builder}. 012 * <p> 013 * Provider profiles reduce boilerplate when creating profile attributes for a 014 * known provider. They set provider names and caller-supplied provider fields 015 * while still allowing the caller to add AI model identifiers, embedding 016 * settings, credentials, and object selection details on 017 * {@link ProfileAttributes.Builder}. 018 * 019 * @see <a href="https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/adbsb/select-ai-manage-profiles.html"> 020 * Select AI provider profile configuration</a> 021 */ 022public abstract class ProviderProfile { 023 /** Embedding model name used by the provider. */ 024 private final String embeddingModel; 025 /** Chat or generation model name used by the provider. */ 026 private final String model; 027 /** Select AI provider identifier. */ 028 private final Provider providerName; 029 /** Provider endpoint host/path used in profile attributes. */ 030 private final String providerEndpoint; 031 /** Provider region, where applicable. */ 032 private final String region; 033 034 /** 035 * Initializes a provider profile from its builder. 036 * 037 * @param builder builder containing the provider profile values 038 */ 039 protected ProviderProfile(Builder<?> builder) { 040 this.embeddingModel = builder.embeddingModel; 041 this.model = builder.model; 042 this.providerName = builder.providerName; 043 this.providerEndpoint = builder.providerEndpoint; 044 this.region = builder.region; 045 } 046 047 /** 048 * Returns the embedding model configured for this provider profile. 049 * 050 * @return embedding model name, or {@code null} when unset 051 */ 052 public String getEmbeddingModel() { 053 return embeddingModel; 054 } 055 056 /** 057 * Returns the chat or generation model configured for this provider profile. 058 * 059 * @return AI model name, or {@code null} when unset 060 */ 061 public String getModel() { 062 return model; 063 } 064 065 /** 066 * Returns the Select AI provider identifier. 067 * 068 * @return provider name, or {@code null} when unset 069 */ 070 public Provider getProviderName() { 071 return providerName; 072 } 073 074 /** 075 * Returns the provider endpoint. 076 * 077 * @return provider endpoint host/path, or {@code null} when unset 078 */ 079 public String getProviderEndpoint() { 080 return providerEndpoint; 081 } 082 083 /** 084 * Returns the provider region. 085 * 086 * @return region value, or {@code null} when unset 087 */ 088 public String getRegion() { 089 return region; 090 } 091 092 /** 093 * Creates a builder for OpenAI provider profile attributes. 094 * 095 * @return OpenAI provider profile builder 096 */ 097 public static OpenAIProviderProfile.Builder openAI() { 098 return new OpenAIProviderProfile.Builder(); 099 } 100 101 /** 102 * Creates a builder for Cohere provider profile attributes. 103 * 104 * @return Cohere provider profile builder 105 */ 106 public static CohereProviderProfile.Builder cohere() { 107 return new CohereProviderProfile.Builder(); 108 } 109 110 /** 111 * Creates a builder for Azure OpenAI provider profile attributes. 112 * 113 * @return Azure provider profile builder 114 */ 115 public static AzureProviderProfile.Builder azure() { 116 return new AzureProviderProfile.Builder(); 117 } 118 119 /** 120 * Creates a builder for OCI Generative AI provider profile attributes. 121 * 122 * @return OCI Generative AI provider profile builder 123 */ 124 public static OCIGenAIProviderProfile.Builder ociGenAI() { 125 return new OCIGenAIProviderProfile.Builder(); 126 } 127 128 /** 129 * Creates a builder for Google provider profile attributes. 130 * 131 * @return Google provider profile builder 132 */ 133 public static GoogleProviderProfile.Builder google() { 134 return new GoogleProviderProfile.Builder(); 135 } 136 137 /** 138 * Creates a builder for Hugging Face provider profile attributes. 139 * 140 * @return Hugging Face provider profile builder 141 */ 142 public static HuggingFaceProviderProfile.Builder huggingFace() { 143 return new HuggingFaceProviderProfile.Builder(); 144 } 145 146 /** 147 * Creates a builder for AWS Bedrock provider profile attributes. 148 * 149 * @return AWS Bedrock provider profile builder 150 */ 151 public static AWSProviderProfile.Builder aws() { 152 return new AWSProviderProfile.Builder(); 153 } 154 155 /** 156 * Creates a builder for Anthropic provider profile attributes. 157 * 158 * @return Anthropic provider profile builder 159 */ 160 public static AnthropicProviderProfile.Builder anthropic() { 161 return new AnthropicProviderProfile.Builder(); 162 } 163 164 /** 165 * Applies this provider profile to a profile attributes builder. 166 * 167 * @param builder profile attributes builder to update 168 * @return the same builder instance after provider fields are applied 169 */ 170 public ProfileAttributes.Builder applyTo(ProfileAttributes.Builder builder) { 171 if (builder == null) { 172 throw new IllegalArgumentException("builder must not be null"); 173 } 174 if (embeddingModel != null) { 175 builder.embeddingModel(embeddingModel); 176 } 177 if (model != null) { 178 builder.model(model); 179 } 180 if (providerName != null) { 181 builder.provider(providerName.name()); 182 } 183 if (providerEndpoint != null) { 184 builder.providerEndpoint(providerEndpoint); 185 } 186 if (region != null) { 187 builder.region(region); 188 } 189 return builder; 190 } 191 192 /** 193 * Base builder for provider profile implementations. 194 * 195 * @param <T> concrete builder type for fluent chaining 196 */ 197 public abstract static class Builder<T extends Builder<T>> { 198 /** Creates an empty provider profile builder. */ 199 public Builder() { 200 } 201 202 /** Embedding model being assembled. */ 203 protected String embeddingModel; 204 /** Chat or generation model being assembled. */ 205 protected String model; 206 /** Provider identifier being assembled. */ 207 protected Provider providerName; 208 /** Provider endpoint being assembled. */ 209 protected String providerEndpoint; 210 /** Provider region being assembled. */ 211 protected String region; 212 213 /** 214 * Returns the concrete builder instance for fluent chaining. 215 * 216 * @return concrete builder instance 217 */ 218 protected abstract T self(); 219 220 /** 221 * Sets the embedding model. 222 * 223 * @param embeddingModel embedding model name 224 * @return this builder instance 225 */ 226 public T embeddingModel(String embeddingModel) { 227 this.embeddingModel = embeddingModel; 228 return self(); 229 } 230 231 /** 232 * Sets the chat or generation model. 233 * 234 * @param model AI model name 235 * @return this builder instance 236 */ 237 public T model(String model) { 238 this.model = model; 239 return self(); 240 } 241 242 /** 243 * Sets the provider identifier. 244 * 245 * @param providerName Select AI provider name 246 * @return this builder instance 247 */ 248 public T providerName(Provider providerName) { 249 this.providerName = providerName; 250 return self(); 251 } 252 253 /** 254 * Sets the provider endpoint. 255 * 256 * @param providerEndpoint provider endpoint host/path 257 * @return this builder instance 258 */ 259 public T providerEndpoint(String providerEndpoint) { 260 this.providerEndpoint = providerEndpoint; 261 return self(); 262 } 263 264 /** 265 * Sets the provider region. 266 * 267 * @param region provider region 268 * @return this builder instance 269 */ 270 public T region(String region) { 271 this.region = region; 272 return self(); 273 } 274 } 275 276 /** 277 * Provider profile attributes for Azure OpenAI. 278 */ 279 public static final class AzureProviderProfile extends ProviderProfile { 280 /** Azure OpenAI deployment used for generation. */ 281 private final String azureDeploymentName; 282 /** Azure OpenAI deployment used for embeddings. */ 283 private final String azureEmbeddingDeploymentName; 284 /** Azure OpenAI resource name. */ 285 private final String azureResourceName; 286 287 private AzureProviderProfile(Builder builder) { 288 super(builder.providerName(Provider.azure) 289 .providerEndpoint(builder.providerEndpoint)); 290 this.azureDeploymentName = builder.azureDeploymentName; 291 this.azureEmbeddingDeploymentName = builder.azureEmbeddingDeploymentName; 292 this.azureResourceName = builder.azureResourceName; 293 } 294 295 /** 296 * Applies Azure-specific attributes to a profile builder. 297 * 298 * @param builder profile attributes builder to update 299 * @return the same builder instance after Azure fields are applied 300 */ 301 @Override 302 public ProfileAttributes.Builder applyTo(ProfileAttributes.Builder builder) { 303 super.applyTo(builder) 304 .azureDeploymentName(azureDeploymentName) 305 .azureEmbeddingDeploymentName(azureEmbeddingDeploymentName) 306 .azureResourceName(azureResourceName); 307 return builder; 308 } 309 310 /** 311 * Builder for {@link AzureProviderProfile}. 312 */ 313 public static class Builder extends ProviderProfile.Builder<Builder> { 314 /** Creates an empty Azure provider profile builder. */ 315 public Builder() { 316 } 317 318 /** Azure OpenAI deployment name being assembled. */ 319 private String azureDeploymentName; 320 /** Azure embedding deployment name being assembled. */ 321 private String azureEmbeddingDeploymentName; 322 /** Azure resource name being assembled. */ 323 private String azureResourceName; 324 325 /** {@inheritDoc} */ 326 @Override 327 protected Builder self() { 328 return this; 329 } 330 331 /** 332 * Sets the Azure OpenAI deployment name. 333 * 334 * @param value deployment name 335 * @return this builder instance 336 */ 337 public Builder azureDeploymentName(String value) { 338 this.azureDeploymentName = value; 339 return this; 340 } 341 342 /** 343 * Sets the Azure OpenAI embedding deployment name. 344 * 345 * @param value embedding deployment name 346 * @return this builder instance 347 */ 348 public Builder azureEmbeddingDeploymentName(String value) { 349 this.azureEmbeddingDeploymentName = value; 350 return this; 351 } 352 353 /** 354 * Sets the Azure OpenAI resource name. 355 * 356 * @param value Azure resource name 357 * @return this builder instance 358 */ 359 public Builder azureResourceName(String value) { 360 this.azureResourceName = value; 361 return this; 362 } 363 364 /** 365 * Builds the Azure provider profile. 366 * 367 * @return Azure provider profile 368 */ 369 public AzureProviderProfile build() { 370 return new AzureProviderProfile(this); 371 } 372 } 373 } 374 375 /** 376 * Provider profile attributes for AWS Bedrock. 377 */ 378 public static final class AWSProviderProfile extends ProviderProfile { 379 /** AWS API format passed as a custom profile attribute. */ 380 private final String awsApiFormat; 381 382 private AWSProviderProfile(Builder builder) { 383 super(builder.providerName(Provider.aws) 384 .providerEndpoint(builder.providerEndpoint)); 385 this.awsApiFormat = builder.awsApiFormat; 386 } 387 388 /** 389 * Applies AWS-specific attributes to a profile builder. 390 * 391 * @param builder profile attributes builder to update 392 * @return the same builder instance after AWS fields are applied 393 */ 394 @Override 395 public ProfileAttributes.Builder applyTo(ProfileAttributes.Builder builder) { 396 super.applyTo(builder); 397 if (awsApiFormat != null) { 398 builder.customAttribute("aws_apiformat", awsApiFormat); 399 } 400 return builder; 401 } 402 403 /** 404 * Builder for {@link AWSProviderProfile}. 405 */ 406 public static class Builder extends ProviderProfile.Builder<Builder> { 407 /** Creates an empty AWS provider profile builder. */ 408 public Builder() { 409 } 410 411 /** AWS API format being assembled. */ 412 private String awsApiFormat; 413 414 /** {@inheritDoc} */ 415 @Override 416 protected Builder self() { 417 return this; 418 } 419 420 /** 421 * Sets the AWS API format custom attribute. 422 * 423 * @param value AWS API format 424 * @return this builder instance 425 */ 426 public Builder awsApiFormat(String value) { 427 this.awsApiFormat = value; 428 return this; 429 } 430 431 /** 432 * Builds the AWS provider profile. 433 * 434 * @return AWS provider profile 435 */ 436 public AWSProviderProfile build() { 437 return new AWSProviderProfile(this); 438 } 439 } 440 } 441 442 /** 443 * Provider profile attributes for OpenAI. 444 */ 445 public static final class OpenAIProviderProfile extends ProviderProfile { 446 private OpenAIProviderProfile(Builder builder) { 447 super(builder.providerName(Provider.openai).providerEndpoint(builder.providerEndpoint)); 448 } 449 450 /** 451 * Builder for {@link OpenAIProviderProfile}. 452 */ 453 public static class Builder extends ProviderProfile.Builder<Builder> { 454 /** Creates an empty OpenAI provider profile builder. */ 455 public Builder() { 456 } 457 458 /** {@inheritDoc} */ 459 @Override 460 protected Builder self() { 461 return this; 462 } 463 464 /** 465 * Builds the OpenAI provider profile. 466 * 467 * @return OpenAI provider profile 468 */ 469 public OpenAIProviderProfile build() { 470 return new OpenAIProviderProfile(this); 471 } 472 } 473 } 474 475 /** 476 * Provider profile attributes for Cohere. 477 */ 478 public static final class CohereProviderProfile extends ProviderProfile { 479 private CohereProviderProfile(Builder builder) { 480 super(builder.providerName(Provider.cohere).providerEndpoint(builder.providerEndpoint)); 481 } 482 483 /** 484 * Builder for {@link CohereProviderProfile}. 485 */ 486 public static class Builder extends ProviderProfile.Builder<Builder> { 487 /** Creates an empty Cohere provider profile builder. */ 488 public Builder() { 489 } 490 491 /** {@inheritDoc} */ 492 @Override 493 protected Builder self() { 494 return this; 495 } 496 497 /** 498 * Builds the Cohere provider profile. 499 * 500 * @return Cohere provider profile 501 */ 502 public CohereProviderProfile build() { 503 return new CohereProviderProfile(this); 504 } 505 } 506 } 507 508 /** 509 * Provider profile attributes for Google. 510 */ 511 public static final class GoogleProviderProfile extends ProviderProfile { 512 private GoogleProviderProfile(Builder builder) { 513 super(builder.providerName(Provider.google).providerEndpoint(builder.providerEndpoint)); 514 } 515 516 /** 517 * Builder for {@link GoogleProviderProfile}. 518 */ 519 public static class Builder extends ProviderProfile.Builder<Builder> { 520 /** Creates an empty Google provider profile builder. */ 521 public Builder() { 522 } 523 524 /** {@inheritDoc} */ 525 @Override 526 protected Builder self() { 527 return this; 528 } 529 530 /** 531 * Builds the Google provider profile. 532 * 533 * @return Google provider profile 534 */ 535 public GoogleProviderProfile build() { 536 return new GoogleProviderProfile(this); 537 } 538 } 539 } 540 541 /** 542 * Provider profile attributes for Hugging Face. 543 */ 544 public static final class HuggingFaceProviderProfile extends ProviderProfile { 545 private HuggingFaceProviderProfile(Builder builder) { 546 super(builder.providerName(Provider.huggingface).providerEndpoint(builder.providerEndpoint)); 547 } 548 549 /** 550 * Builder for {@link HuggingFaceProviderProfile}. 551 */ 552 public static class Builder extends ProviderProfile.Builder<Builder> { 553 /** Creates an empty Hugging Face provider profile builder. */ 554 public Builder() { 555 } 556 557 /** {@inheritDoc} */ 558 @Override 559 protected Builder self() { 560 return this; 561 } 562 563 /** 564 * Builds the Hugging Face provider profile. 565 * 566 * @return Hugging Face provider profile 567 */ 568 public HuggingFaceProviderProfile build() { 569 return new HuggingFaceProviderProfile(this); 570 } 571 } 572 } 573 574 /** 575 * Provider profile attributes for Anthropic. 576 */ 577 public static final class AnthropicProviderProfile extends ProviderProfile { 578 private AnthropicProviderProfile(Builder builder) { 579 super(builder.providerName(Provider.anthropic).providerEndpoint(builder.providerEndpoint)); 580 } 581 582 /** 583 * Builder for {@link AnthropicProviderProfile}. 584 */ 585 public static class Builder extends ProviderProfile.Builder<Builder> { 586 /** Creates an empty Anthropic provider profile builder. */ 587 public Builder() { 588 } 589 590 /** {@inheritDoc} */ 591 @Override 592 protected Builder self() { 593 return this; 594 } 595 596 /** 597 * Builds the Anthropic provider profile. 598 * 599 * @return Anthropic provider profile 600 */ 601 public AnthropicProviderProfile build() { 602 return new AnthropicProviderProfile(this); 603 } 604 } 605 } 606 607 /** 608 * Provider profile attributes for OCI Generative AI. 609 */ 610 public static final class OCIGenAIProviderProfile extends ProviderProfile { 611 /** OCI API format profile attribute. */ 612 private final String ociApiFormat; 613 /** OCI compartment OCID profile attribute. */ 614 private final String ociCompartmentId; 615 /** OCI dedicated endpoint OCID profile attribute. */ 616 private final String ociEndpointId; 617 /** OCI runtime type profile attribute. */ 618 private final String ociRuntimeType; 619 620 private OCIGenAIProviderProfile(Builder builder) { 621 super(builder.providerName(Provider.oci)); 622 this.ociApiFormat = builder.ociApiFormat; 623 this.ociCompartmentId = builder.ociCompartmentId; 624 this.ociEndpointId = builder.ociEndpointId; 625 this.ociRuntimeType = builder.ociRuntimeType; 626 } 627 628 /** 629 * Applies OCI-specific attributes to a profile builder. 630 * 631 * @param builder profile attributes builder to update 632 * @return the same builder instance after OCI fields are applied 633 */ 634 @Override 635 public ProfileAttributes.Builder applyTo(ProfileAttributes.Builder builder) { 636 super.applyTo(builder) 637 .ociApiformat(ociApiFormat) 638 .ociCompartmentId(ociCompartmentId) 639 .ociEndpointId(ociEndpointId) 640 .ociRuntimetype(ociRuntimeType); 641 return builder; 642 } 643 644 /** 645 * Builder for {@link OCIGenAIProviderProfile}. 646 */ 647 public static class Builder extends ProviderProfile.Builder<Builder> { 648 /** Creates an empty OCI Generative AI provider profile builder. */ 649 public Builder() { 650 } 651 652 /** OCI API format being assembled. */ 653 private String ociApiFormat; 654 /** OCI compartment OCID being assembled. */ 655 private String ociCompartmentId; 656 /** OCI endpoint OCID being assembled. */ 657 private String ociEndpointId; 658 /** OCI runtime type being assembled. */ 659 private String ociRuntimeType; 660 661 /** {@inheritDoc} */ 662 @Override 663 protected Builder self() { 664 return this; 665 } 666 667 /** 668 * Sets the OCI API format. 669 * 670 * @param value OCI API format 671 * @return this builder instance 672 */ 673 public Builder ociApiFormat(String value) { 674 this.ociApiFormat = value; 675 return this; 676 } 677 678 /** 679 * Sets the OCI API format. 680 * 681 * @param value OCI API format 682 * @return this builder instance 683 */ 684 public Builder ociApiFormat(OciApiFormat value) { 685 this.ociApiFormat = value == null ? null : value.getValue(); 686 return this; 687 } 688 689 /** 690 * Sets the OCI compartment OCID. 691 * 692 * @param value compartment OCID 693 * @return this builder instance 694 */ 695 public Builder ociCompartmentId(String value) { 696 this.ociCompartmentId = value; 697 return this; 698 } 699 700 /** 701 * Sets the OCI dedicated endpoint OCID. 702 * 703 * @param value endpoint OCID 704 * @return this builder instance 705 */ 706 public Builder ociEndpointId(String value) { 707 this.ociEndpointId = value; 708 return this; 709 } 710 711 /** 712 * Sets the OCI runtime type. 713 * 714 * @param value runtime type 715 * @return this builder instance 716 */ 717 public Builder ociRuntimeType(String value) { 718 this.ociRuntimeType = value; 719 return this; 720 } 721 722 /** 723 * Builds the OCI Generative AI provider profile. 724 * 725 * @return OCI Generative AI provider profile 726 */ 727 public OCIGenAIProviderProfile build() { 728 return new OCIGenAIProviderProfile(this); 729 } 730 } 731 } 732}