Skip to content

Commit

Permalink
[agents] Makes "access-key" property for OpenAIConfig optional. Omitt…
Browse files Browse the repository at this point in the history
…ing API key allows HTTP schema for internal cluster communications, without receiving "Key credentials require HTTPS to prevent leaking the key." error.
  • Loading branch information
Dobosz committed Nov 27, 2023
1 parent eec9581 commit eab5425
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class OpenAIConfig {
@JsonProperty private String url;

@JsonProperty(value = "access-key", required = true)
@JsonProperty(value = "access-key")
private String accessKey;

@JsonProperty OpenAIProvider provider = OpenAIProvider.OPENAI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ public static OpenAIClient buildOpenAIClient(OpenAIConfig openAIConfig) {
return null;
}
OpenAIClientBuilder openAIClientBuilder = new OpenAIClientBuilder();
if (openAIConfig.getProvider() == OpenAIProvider.AZURE) {
openAIClientBuilder.credential(new AzureKeyCredential(openAIConfig.getAccessKey()));
} else {
openAIClientBuilder.credential(new KeyCredential(openAIConfig.getAccessKey()));
if (!openAIConfig.getAccessKey().isEmpty()) {
if (openAIConfig.getProvider() == OpenAIProvider.AZURE) {
openAIClientBuilder.credential(new AzureKeyCredential(openAIConfig.getAccessKey()));
} else {
openAIClientBuilder.credential(new KeyCredential(openAIConfig.getAccessKey()));
}
}
if (openAIConfig.getUrl() != null && !openAIConfig.getUrl().isEmpty()) {
openAIClientBuilder.endpoint(openAIConfig.getUrl());
Expand All @@ -124,10 +126,12 @@ public static OpenAIAsyncClient buildOpenAsyncAIClient(OpenAIConfig openAIConfig
return null;
}
OpenAIClientBuilder openAIClientBuilder = new OpenAIClientBuilder();
if (openAIConfig.getProvider() == OpenAIProvider.AZURE) {
openAIClientBuilder.credential(new AzureKeyCredential(openAIConfig.getAccessKey()));
} else {
openAIClientBuilder.credential(new KeyCredential(openAIConfig.getAccessKey()));
if (!openAIConfig.getAccessKey().isEmpty()) {
if (openAIConfig.getProvider() == OpenAIProvider.AZURE) {
openAIClientBuilder.credential(new AzureKeyCredential(openAIConfig.getAccessKey()));
} else {
openAIClientBuilder.credential(new KeyCredential(openAIConfig.getAccessKey()));
}
}
if (openAIConfig.getUrl() != null && !openAIConfig.getUrl().isEmpty()) {
openAIClientBuilder.endpoint(openAIConfig.getUrl());
Expand Down

0 comments on commit eab5425

Please sign in to comment.