diff --git a/src/main/java/ee/carlrobert/codegpt/completions/CompletionClientProvider.java b/src/main/java/ee/carlrobert/codegpt/completions/CompletionClientProvider.java index 4ce48d514..aa402d2f0 100644 --- a/src/main/java/ee/carlrobert/codegpt/completions/CompletionClientProvider.java +++ b/src/main/java/ee/carlrobert/codegpt/completions/CompletionClientProvider.java @@ -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()); diff --git a/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsForm.java b/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsForm.java index 72e59c0b6..a754e9453 100644 --- a/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsForm.java +++ b/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsForm.java @@ -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; @@ -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(() -> { @@ -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( @@ -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()); diff --git a/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsState.java b/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsState.java index b322753c9..567ec5b4d 100644 --- a/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsState.java +++ b/src/main/java/ee/carlrobert/codegpt/settings/service/watsonx/WatsonxSettingsState.java @@ -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"; @@ -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; } @@ -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); } } diff --git a/src/main/resources/messages/codegpt.properties b/src/main/resources/messages/codegpt.properties index f21316f04..11ce1eeed 100644 --- a/src/main/resources/messages/codegpt.properties +++ b/src/main/resources/messages/codegpt.properties @@ -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