Skip to content

Commit

Permalink
cloud region customization
Browse files Browse the repository at this point in the history
  • Loading branch information
mq200 committed Sep 6, 2024
1 parent f8de422 commit 912531d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ public static CodeGPTClient getCodeGPTClient() {
}

public static WatsonxClient getWatsonxClient() {
String regionCode = switch(WatsonxSettings.getCurrentState().getRegion()) {
case "Dallas" -> "us-south";
case "Frankfurt" -> "eu-de";
case "London" -> "eu-gb";
case "Tokyo" -> "jp-tok";
default -> "us-south";
};
String host = WatsonxSettings.getCurrentState().isOnPrem() ? WatsonxSettings.getCurrentState().getOnPremHost() : "https://" + regionCode + ".ml.cloud.ibm.com";
return new WatsonxClient.Builder(getCredential(CredentialKey.WATSONX_API_KEY))
.setApiVersion(WatsonxSettings.getCurrentState().getApiVersion())
.setIsOnPrem(WatsonxSettings.getCurrentState().isOnPrem())
.setHost(WatsonxSettings.getCurrentState().getOnPremHost())
.setHost(host)
.setUsername(WatsonxSettings.getCurrentState().getUsername())
.setIsZenApiKey(WatsonxSettings.getCurrentState().isZenApiKey())
.build(getDefaultClientBuilder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class WatsonxSettingsForm {
private final JBCheckBox onPremCheckbox;
private final JBPasswordField apiKeyField;
private final JBPasswordField onPremApiKeyField;
private final ComboBox regionComboBox;
private final JBTextField onPremHostField;
private final JBTextField usernameField;
private final JBCheckBox zenApiKeyCheckbox;
Expand Down Expand Up @@ -82,6 +83,9 @@ class OpenUrlAction implements ActionListener {
getStartedLink.setToolTipText(getStartedUrl);
getStartedLink.addActionListener(new OpenUrlAction());

regionComboBox = new ComboBox(new String[] {"Dallas", "Frankfurt", "London", "Tokyo"});
regionComboBox.setSelectedItem(settings.getRegion());

apiKeyField = new JBPasswordField();
apiKeyField.setColumns(35);
ApplicationManager.getApplication().executeOnPooledThread(() -> {
Expand Down Expand Up @@ -117,6 +121,10 @@ class OpenUrlAction implements ActionListener {

onCloudAuthenticationFieldPanel = new UI.PanelFactory().grid()
.add(UI.PanelFactory.panel(getStartedLink))
.add(UI.PanelFactory.panel(regionComboBox)
.withLabel(CodeGPTBundle.get("settingsConfigurable.service.watsonx.cloudRegion.label"))
.withComment(CodeGPTBundle.get("settingsConfigurable.service.watsonx.cloudRegion.comment"))
.resizeX(false))
.add(UI.PanelFactory.panel(apiKeyField)
.withLabel(CodeGPTBundle.get("settingsConfigurable.service.watsonx.onCloudApiKey.label"))
.withComment(CodeGPTBundle.get(
Expand Down Expand Up @@ -258,6 +266,7 @@ public WatsonxSettingsState getCurrentState() {
state.setOnPremHost(onPremHostField.getText());
state.setUsername(usernameField.getText());
state.setZenApiKey(zenApiKeyCheckbox.isSelected());
state.setRegion((String)regionComboBox.getSelectedItem());
state.setApiVersion(apiVersionField.getText());
state.setSpaceId(spaceIdField.getText());
state.setProjectId(projectIdField.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class WatsonxSettingsState {
private String username;
private boolean isOnPrem = false;
private boolean isZenApiKey = false;
private String region = "us-south";
private String apiVersion = "2024-03-14";
// use this model as default
private String model = "ibm/granite-3b-code-instruct";
Expand Down Expand Up @@ -57,6 +58,12 @@ public void setUsername(String username) {
this.username = username;
}

public String getRegion() {return region;}

public void setRegion(String region) {
this.region = region;
}

public String getApiVersion() {
return apiVersion;
}
Expand Down Expand Up @@ -170,12 +177,10 @@ public boolean equals(Object o) {
return false;
}
ee.carlrobert.codegpt.settings.service.watsonx.WatsonxSettingsState that = (ee.carlrobert.codegpt.settings.service.watsonx.WatsonxSettingsState) o;
return Objects.equals(apiVersion, that.apiVersion) && Objects.equals(spaceId, that.spaceId) && Objects.equals(projectId, that.projectId) && Objects.equals(model, that.model) && Objects.equals(temperature,that.temperature) && Objects.equals(topP,that.topP) && Objects.equals(topK,that.topK) && Objects.equals(randomSeed,that.randomSeed) && Objects.equals(repetitionPenalty,that.repetitionPenalty) && Objects.equals(maxNewTokens, that.maxNewTokens) && Objects.equals(minNewTokens,that.minNewTokens) && Objects.equals(isGreedyDecoding,that.isGreedyDecoding) && Objects.equals(isOnPrem,that.isOnPrem) && Objects.equals(isZenApiKey,that.isZenApiKey);

return Objects.equals(apiVersion, that.apiVersion) && Objects.equals(region, that.region) && Objects.equals(spaceId, that.spaceId) && Objects.equals(projectId, that.projectId) && Objects.equals(model, that.model) && Objects.equals(temperature,that.temperature) && Objects.equals(topP,that.topP) && Objects.equals(topK,that.topK) && Objects.equals(randomSeed,that.randomSeed) && Objects.equals(repetitionPenalty,that.repetitionPenalty) && Objects.equals(maxNewTokens, that.maxNewTokens) && Objects.equals(minNewTokens,that.minNewTokens) && Objects.equals(isGreedyDecoding,that.isGreedyDecoding) && Objects.equals(isOnPrem,that.isOnPrem) && Objects.equals(isZenApiKey,that.isZenApiKey);
}

@Override
public int hashCode() {
return Objects.hash(apiVersion, model, apiVersion, projectId, spaceId,temperature,topP,topK,randomSeed,includeStopSequence,stopSequences,repetitionPenalty, maxNewTokens,minNewTokens,isGreedyDecoding,isOnPrem,isZenApiKey);
}
return Objects.hash(apiVersion, region, model, apiVersion, projectId, spaceId,temperature,topP,topK,randomSeed,includeStopSequence,stopSequences,repetitionPenalty, maxNewTokens,minNewTokens,isGreedyDecoding,isOnPrem,isZenApiKey); }
}
2 changes: 2 additions & 0 deletions src/main/resources/messages/codegpt.properties
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ settingsConfigurable.service.watsonx.minNewTokens.label=Min completion tokens:
settingsConfigurable.service.watsonx.stopSequences.label=Stop sequences
settingsConfigurable.service.watsonx.stopSequences.comment=Comma-separated list of stop sequences
settingsConfigurable.service.watsonx.repetitionPenalty.comment=
settingsConfigurable.service.watsonx.cloudRegion.label=IBM Cloud region:
settingsConfigurable.service.watsonx.cloudRegion.comment=
configurationConfigurable.section.commitMessage.title=Commit Message Template
configurationConfigurable.section.commitMessage.systemPromptField.label=Prompt template:
configurationConfigurable.section.inlineCompletion.title=Inline Completion
Expand Down

0 comments on commit 912531d

Please sign in to comment.