Skip to content

Commit 912531d

Browse files
committed
cloud region customization
1 parent f8de422 commit 912531d

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/main/java/ee/carlrobert/codegpt/completions/CompletionClientProvider.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ public static CodeGPTClient getCodeGPTClient() {
3535
}
3636

3737
public static WatsonxClient getWatsonxClient() {
38+
String regionCode = switch(WatsonxSettings.getCurrentState().getRegion()) {
39+
case "Dallas" -> "us-south";
40+
case "Frankfurt" -> "eu-de";
41+
case "London" -> "eu-gb";
42+
case "Tokyo" -> "jp-tok";
43+
default -> "us-south";
44+
};
45+
String host = WatsonxSettings.getCurrentState().isOnPrem() ? WatsonxSettings.getCurrentState().getOnPremHost() : "https://" + regionCode + ".ml.cloud.ibm.com";
3846
return new WatsonxClient.Builder(getCredential(CredentialKey.WATSONX_API_KEY))
3947
.setApiVersion(WatsonxSettings.getCurrentState().getApiVersion())
4048
.setIsOnPrem(WatsonxSettings.getCurrentState().isOnPrem())
41-
.setHost(WatsonxSettings.getCurrentState().getOnPremHost())
49+
.setHost(host)
4250
.setUsername(WatsonxSettings.getCurrentState().getUsername())
4351
.setIsZenApiKey(WatsonxSettings.getCurrentState().isZenApiKey())
4452
.build(getDefaultClientBuilder());

src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsForm.java

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class WatsonxSettingsForm {
3333
private final JBCheckBox onPremCheckbox;
3434
private final JBPasswordField apiKeyField;
3535
private final JBPasswordField onPremApiKeyField;
36+
private final ComboBox regionComboBox;
3637
private final JBTextField onPremHostField;
3738
private final JBTextField usernameField;
3839
private final JBCheckBox zenApiKeyCheckbox;
@@ -82,6 +83,9 @@ class OpenUrlAction implements ActionListener {
8283
getStartedLink.setToolTipText(getStartedUrl);
8384
getStartedLink.addActionListener(new OpenUrlAction());
8485

86+
regionComboBox = new ComboBox(new String[] {"Dallas", "Frankfurt", "London", "Tokyo"});
87+
regionComboBox.setSelectedItem(settings.getRegion());
88+
8589
apiKeyField = new JBPasswordField();
8690
apiKeyField.setColumns(35);
8791
ApplicationManager.getApplication().executeOnPooledThread(() -> {
@@ -117,6 +121,10 @@ class OpenUrlAction implements ActionListener {
117121

118122
onCloudAuthenticationFieldPanel = new UI.PanelFactory().grid()
119123
.add(UI.PanelFactory.panel(getStartedLink))
124+
.add(UI.PanelFactory.panel(regionComboBox)
125+
.withLabel(CodeGPTBundle.get("settingsConfigurable.service.watsonx.cloudRegion.label"))
126+
.withComment(CodeGPTBundle.get("settingsConfigurable.service.watsonx.cloudRegion.comment"))
127+
.resizeX(false))
120128
.add(UI.PanelFactory.panel(apiKeyField)
121129
.withLabel(CodeGPTBundle.get("settingsConfigurable.service.watsonx.onCloudApiKey.label"))
122130
.withComment(CodeGPTBundle.get(
@@ -258,6 +266,7 @@ public WatsonxSettingsState getCurrentState() {
258266
state.setOnPremHost(onPremHostField.getText());
259267
state.setUsername(usernameField.getText());
260268
state.setZenApiKey(zenApiKeyCheckbox.isSelected());
269+
state.setRegion((String)regionComboBox.getSelectedItem());
261270
state.setApiVersion(apiVersionField.getText());
262271
state.setSpaceId(spaceIdField.getText());
263272
state.setProjectId(projectIdField.getText());

src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsState.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class WatsonxSettingsState {
88
private String username;
99
private boolean isOnPrem = false;
1010
private boolean isZenApiKey = false;
11+
private String region = "us-south";
1112
private String apiVersion = "2024-03-14";
1213
// use this model as default
1314
private String model = "ibm/granite-3b-code-instruct";
@@ -57,6 +58,12 @@ public void setUsername(String username) {
5758
this.username = username;
5859
}
5960

61+
public String getRegion() {return region;}
62+
63+
public void setRegion(String region) {
64+
this.region = region;
65+
}
66+
6067
public String getApiVersion() {
6168
return apiVersion;
6269
}
@@ -170,12 +177,10 @@ public boolean equals(Object o) {
170177
return false;
171178
}
172179
ee.carlrobert.codegpt.settings.service.watsonx.WatsonxSettingsState that = (ee.carlrobert.codegpt.settings.service.watsonx.WatsonxSettingsState) o;
173-
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);
174-
180+
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);
175181
}
176182

177183
@Override
178184
public int hashCode() {
179-
return Objects.hash(apiVersion, model, apiVersion, projectId, spaceId,temperature,topP,topK,randomSeed,includeStopSequence,stopSequences,repetitionPenalty, maxNewTokens,minNewTokens,isGreedyDecoding,isOnPrem,isZenApiKey);
180-
}
185+
return Objects.hash(apiVersion, region, model, apiVersion, projectId, spaceId,temperature,topP,topK,randomSeed,includeStopSequence,stopSequences,repetitionPenalty, maxNewTokens,minNewTokens,isGreedyDecoding,isOnPrem,isZenApiKey); }
181186
}

src/main/resources/messages/codegpt.properties

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ settingsConfigurable.service.watsonx.minNewTokens.label=Min completion tokens:
164164
settingsConfigurable.service.watsonx.stopSequences.label=Stop sequences
165165
settingsConfigurable.service.watsonx.stopSequences.comment=Comma-separated list of stop sequences
166166
settingsConfigurable.service.watsonx.repetitionPenalty.comment=
167+
settingsConfigurable.service.watsonx.cloudRegion.label=IBM Cloud region:
168+
settingsConfigurable.service.watsonx.cloudRegion.comment=
167169
configurationConfigurable.section.commitMessage.title=Commit Message Template
168170
configurationConfigurable.section.commitMessage.systemPromptField.label=Prompt template:
169171
configurationConfigurable.section.inlineCompletion.title=Inline Completion

0 commit comments

Comments
 (0)