Skip to content

Commit

Permalink
Move some of the labels to codegpt bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh committed Nov 2, 2023
1 parent d683060 commit e41fa85
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static String[][] toArray(Map<String, String> actionsMap) {
}

public static void refreshActions() {
AnAction actionGroup = ActionManager.getInstance().getAction("action.editor.group.EditorActionGroup");
AnAction actionGroup = ActionManager.getInstance().getAction("project.label");
if (actionGroup instanceof DefaultActionGroup) {
DefaultActionGroup group = (DefaultActionGroup) actionGroup;
group.removeAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public LlamaCompletionRequest buildLlamaCompletionRequest(Message message) {
COMPLETION_SYSTEM_PROMPT,
message.getPrompt(),
conversation.getMessages());
System.out.println("Prompt: " + prompt);
return new LlamaCompletionRequest.Builder(prompt)
.setN_predict(512)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private ProcessListener getMakeProcessListener(
return new ProcessAdapter() {
@Override
public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
System.out.println(event.getText()); // TODO
LOG.info(event.getText());
}

Expand Down Expand Up @@ -103,7 +102,7 @@ public void processTerminated(@NotNull ProcessEvent event) {

@Override
public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
System.out.println(event.getText()); // TODO
LOG.debug(event.getText());

if (outputType == ProcessOutputType.STDOUT) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public SettingsComponent(Disposable parentDisposable, SettingsState settings) {

mainPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(
CodeGPTBundle.get("settingsConfigurable.section.integration.displayNameFieldLabel"),
CodeGPTBundle.get("settingsConfigurable.displayName.label"),
displayNameField)
.addLabeledComponent("Service:", serviceComboBox)
.addLabeledComponent(
CodeGPTBundle.get("settingsConfigurable.service.label"),
serviceComboBox)
.addComponent(cards)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
Expand Down Expand Up @@ -98,7 +100,9 @@ private ComponentValidator createInputValidator(
var selectedItem = ((ComboBox<?>) component).getSelectedItem();
if (selectedItem == ServiceType.OPENAI &&
OpenAISettingsState.getInstance().isOpenAIQuotaExceeded()) {
return new ValidationInfo("OpenAI quota exceeded.", component);
return new ValidationInfo(
CodeGPTBundle.get("settings.openaiQuotaExceeded"),
component);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public AdvancedSettingsComponent(AdvancedSettingsState advancedSettings) {
proxyTypeComboBox.setSelectedItem(advancedSettings.getProxyType());
proxyHostField = new JBTextField(advancedSettings.getProxyHost(), 20);
proxyPortField = new PortField();
proxyAuthCheckbox = new JBCheckBox(CodeGPTBundle.get("advancedSettingsConfigurable.section.proxy.authCheckBoxField.label"));
proxyAuthCheckbox = new JBCheckBox(CodeGPTBundle.get(
"advancedSettingsConfigurable.proxy.authCheckBoxField.label"));
proxyAuthUsername = new JBTextField(20);
proxyAuthUsername.setEnabled(advancedSettings.isProxyAuthSelected());
proxyAuthPassword = new JBPasswordField();
Expand All @@ -52,19 +53,20 @@ public AdvancedSettingsComponent(AdvancedSettingsState advancedSettings) {
readTimeoutField = new PortField(advancedSettings.getReadTimeout());

mainPanel = FormBuilder.createFormBuilder()
.addComponent(new TitledSeparator(CodeGPTBundle.get("advancedSettingsConfigurable.section.proxy.title")))
.addComponent(new TitledSeparator(CodeGPTBundle.get(
"advancedSettingsConfigurable.proxy.title")))
.addComponent(createProxySettingsForm())
.addVerticalGap(4)
.addComponent(new TitledSeparator("Connection Settings"))
.addComponent(new TitledSeparator(CodeGPTBundle.get("advancedSettingsConfigurable.connectionSettings.title")))
.addComponent(createConnectionSettingsForm())
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
}

private JPanel createConnectionSettingsForm() {
var panel = FormBuilder.createFormBuilder()
.addLabeledComponent("Connection timeout (s):", connectionTimeoutField)
.addLabeledComponent("Read timeout (s):", readTimeoutField)
.addLabeledComponent(CodeGPTBundle.get("advancedSettingsConfigurable.connectionSettings.connectionTimeout.label"), connectionTimeoutField)
.addLabeledComponent(CodeGPTBundle.get("advancedSettingsConfigurable.connectionSettings.readTimeout.label"), readTimeoutField)
.getPanel();
panel.setBorder(JBUI.Borders.emptyLeft(16));
return panel;
Expand Down Expand Up @@ -145,15 +147,15 @@ private JComponent createProxySettingsForm() {

var proxyTypePanel = SwingUtils.createPanel(
proxyTypeComboBox,
CodeGPTBundle.get("advancedSettingsConfigurable.section.proxy.typeComboBoxField.label"),
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.typeComboBoxField.label"),
false);
var proxyHostPanel = SwingUtils.createPanel(
proxyHostField,
CodeGPTBundle.get("advancedSettingsConfigurable.section.proxy.hostField.label"),
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.hostField.label"),
false);
var proxyPortPanel = SwingUtils.createPanel(
proxyPortField,
CodeGPTBundle.get("advancedSettingsConfigurable.section.proxy.portField.label"),
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.portField.label"),
false);
SwingUtils.setEqualLabelWidths(proxyTypePanel, proxyHostPanel);
SwingUtils.setEqualLabelWidths(proxyPortPanel, proxyHostPanel);
Expand All @@ -166,10 +168,10 @@ private JComponent createProxySettingsForm() {
.createPanel());

var proxyUsernamePanel = SwingUtils.createPanel(proxyAuthUsername,
CodeGPTBundle.get("advancedSettingsConfigurable.section.proxy.usernameField.label"),
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.usernameField.label"),
false);
var proxyPasswordPanel = SwingUtils.createPanel(proxyAuthPassword,
CodeGPTBundle.get("advancedSettingsConfigurable.section.proxy.passwordField.label"),
CodeGPTBundle.get("advancedSettingsConfigurable.proxy.passwordField.label"),
false);
SwingUtils.setEqualLabelWidths(proxyPasswordPanel, proxyUsernamePanel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ private ComponentValidator createInputValidator(Disposable parentDisposable, JBT
try {
var value = Double.parseDouble(valueText);
if (value > 1.0 || value < 0.0) {
return new ValidationInfo("Value must be between 0 and 1.", component);
return new ValidationInfo(CodeGPTBundle.get("validation.error.mustBeBetweenZeroAndOne"), component);
}
} catch (NumberFormatException e) {
return new ValidationInfo("Value must be number.", component);
return new ValidationInfo(CodeGPTBundle.get("validation.error.mustBeNumber"), component);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import ee.carlrobert.codegpt.CodeGPTBundle;
import ee.carlrobert.codegpt.completions.HuggingFaceModel;
import ee.carlrobert.codegpt.util.DownloadingUtils;
import ee.carlrobert.codegpt.util.file.FileUtils;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
class DownloadBackgroundTask extends Task.Backgroundable {

DownloadBackgroundTask(Project project) {
super(project, "Downloading Model", true);
super(project, CodeGPTBundle.get("settingsConfigurable.service.llama.progress.downloadingModel.title"), true);
}

@Override
Expand All @@ -67,7 +68,7 @@ public void run(@NotNull ProgressIndicator indicator) {
onDownload.accept(indicator);

indicator.setIndeterminate(false);
indicator.setText(format("Downloading %s...", model.getFileName()));
indicator.setText(format(CodeGPTBundle.get("settingsConfigurable.service.llama.progress.downloadingModelIndicator.text"), model.getFileName()));

long fileSize = url.openConnection().getContentLengthLong();
long[] bytesRead = {0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.JBUI;
import ee.carlrobert.codegpt.CodeGPTBundle;
import ee.carlrobert.codegpt.CodeGPTPlugin;
import ee.carlrobert.codegpt.completions.HuggingFaceModel;
import ee.carlrobert.codegpt.completions.llama.LlamaModel;
Expand Down Expand Up @@ -80,6 +81,7 @@ public LlamaModelPreferencesForm() {
var llamaSettings = LlamaSettingsState.getInstance();
customModelPathBrowserButton = createCustomModelPathBrowseButton(
llamaSettings.isUseCustomModel() && !llamaServerAgent.isServerRunning());
customModelPathBrowserButton.setText(llamaSettings.getCustomLlamaModelPath());
progressLabel = new JBLabel("");
progressLabel.setBorder(JBUI.Borders.emptyLeft(2));
progressLabel.setFont(JBUI.Fonts.smallFont());
Expand Down Expand Up @@ -123,10 +125,12 @@ public LlamaModelPreferencesForm() {
huggingFaceComboBoxModel);
modelSizeComboBox.setEnabled(initialModelSizes.size() > 1);
promptTemplateComboBox = new ComboBox<>(new EnumComboBoxModel<>(PromptTemplate.class));
promptTemplateComboBox.setSelectedItem(llamaSettings.getPromptTemplate());
promptTemplateComboBox.setEnabled(
llamaSettings.isUseCustomModel() && !llamaServerAgent.isServerRunning());
promptTemplateComboBox.setPreferredSize(modelComboBox.getPreferredSize());
useCustomModelCheckBox = new JBCheckBox("Use custom model");
useCustomModelCheckBox = new JBCheckBox(CodeGPTBundle.get(
"settingsConfigurable.service.llama.useCustomModel.label"), llamaSettings.isUseCustomModel());
useCustomModelCheckBox.setEnabled(!llamaServerAgent.isServerRunning());
useCustomModelCheckBox.addChangeListener(e -> {
var selected = ((JBCheckBox) e.getSource()).isSelected();
Expand All @@ -140,11 +144,11 @@ public LlamaModelPreferencesForm() {

public JPanel getForm() {
var customModelHelpText = ComponentPanelBuilder.createCommentComponent(
"Only .gguf files are supported",
CodeGPTBundle.get("settingsConfigurable.service.llama.customModelPath.comment"),
true);
customModelHelpText.setBorder(JBUI.Borders.empty(0, 4));
var quantizationHelpText = ComponentPanelBuilder.createCommentComponent(
"Quantization is a technique to reduce the computational and memory costs of running inference. <a href=\"https://huggingface.co/docs/optimum/concept_guides/quantization\">Learn more</a>",
CodeGPTBundle.get("settingsConfigurable.service.llama.quantization.comment"),
true);
quantizationHelpText.setBorder(JBUI.Borders.empty(0, 4));

Expand All @@ -161,16 +165,16 @@ public JPanel getForm() {
huggingFaceModelComboBoxWrapper.add(modelDetailsLabel);

return FormBuilder.createFormBuilder()
.addLabeledComponent("Model:", modelComboBoxWrapper)
.addLabeledComponent("Model size:", modelSizeComboBox)
.addLabeledComponent("Quantization:", huggingFaceModelComboBoxWrapper)
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.shared.model.label"), modelComboBoxWrapper)
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.llama.modelSize.label"), modelSizeComboBox)
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.llama.quantization.label"), huggingFaceModelComboBoxWrapper)
.addComponentToRightColumn(quantizationHelpText)
.addComponentToRightColumn(downloadModelActionLinkWrapper)
.addComponentToRightColumn(progressLabel)
.addVerticalGap(8)
.addComponent(useCustomModelCheckBox)
.addLabeledComponent("Prompt template:", promptTemplateComboBox)
.addLabeledComponent("Model path:", customModelPathBrowserButton)
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.llama.promptTemplate.label"), promptTemplateComboBox)
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.llama.customModelPath.label"), customModelPathBrowserButton)
.addComponentToRightColumn(customModelHelpText)
.addVerticalGap(4)
.getPanel();
Expand Down Expand Up @@ -325,7 +329,6 @@ private ComboBox<HuggingFaceModel> createHuggingFaceComboBox(
private TextFieldWithBrowseButton createCustomModelPathBrowseButton(boolean enabled) {
var browseButton = new TextFieldWithBrowseButton();
browseButton.setEnabled(enabled);
browseButton.setText(CodeGPTPlugin.getLlamaModelsPath());

var fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor("gguf");
fileChooserDescriptor.setForcedToUseIdeaFileChooser(true);
Expand All @@ -344,7 +347,7 @@ private AnActionLink createCancelDownloadLink(
JPanel actionLinkWrapper,
DefaultComboBoxModel<HuggingFaceModel> huggingFaceComboBoxModel,
ProgressIndicator progressIndicator) {
return new AnActionLink("Cancel Downloading", new AnAction() {
return new AnActionLink(CodeGPTBundle.get("settingsConfigurable.service.llama.cancelDownloadLink.label"), new AnAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
SwingUtilities.invokeLater(() -> {
Expand Down Expand Up @@ -378,7 +381,7 @@ private AnActionLink createDownloadModelLink(
JBLabel progressLabel,
JPanel actionLinkWrapper,
DefaultComboBoxModel<HuggingFaceModel> huggingFaceComboBoxModel) {
return new AnActionLink("Download Model", new DownloadModelAction(
return new AnActionLink(CodeGPTBundle.get("settingsConfigurable.service.llama.downloadModelLink.label"), new DownloadModelAction(
progressIndicator -> {
SwingUtilities.invokeLater(() -> {
configureFieldsForDownloading(true);
Expand Down Expand Up @@ -413,7 +416,7 @@ private void updateModelHelpTooltip(HuggingFaceModel model) {
new HelpTooltip()
.setTitle(llamaModel.getLabel())
.setDescription("<html><p>" + llamaModel.getDescription() + "</p></html>")
.setBrowserLink("Link to model", model.getHuggingFaceURL())
.setBrowserLink(CodeGPTBundle.get("settingsConfigurable.service.llama.linkToModel.label"), model.getHuggingFaceURL())
.installOn(helpIcon);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.intellij.ui.components.fields.IntegerField;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.JBUI;
import ee.carlrobert.codegpt.CodeGPTBundle;
import ee.carlrobert.codegpt.CodeGPTPlugin;
import ee.carlrobert.codegpt.completions.HuggingFaceModel;
import ee.carlrobert.codegpt.completions.llama.LlamaServerAgent;
Expand Down Expand Up @@ -42,22 +43,24 @@ public LlamaServiceSelectionForm() {
maxTokensField.setEnabled(!serverRunning);

var serverButton = new JButton();
serverButton.setText(serverRunning ? "Stop Server" : "Start Server");
serverButton.setText(serverRunning ?
CodeGPTBundle.get("settingsConfigurable.service.llama.stopServer.label") :
CodeGPTBundle.get("settingsConfigurable.service.llama.startServer.label"));
serverButton.setIcon(serverRunning ? Actions.Suspend : Actions.Execute);
serverButton.addActionListener(event -> {
if (llamaModelPreferencesForm.isUseCustomLlamaModel()) {
var customModelPath = llamaModelPreferencesForm.getCustomLlamaModelPath();
if (customModelPath == null || customModelPath.isEmpty()) {
OverlayUtils.showBalloon(
"This is a required field",
CodeGPTBundle.get("validation.error.fieldRequired"),
MessageType.ERROR,
llamaModelPreferencesForm.getCustomModelPathBrowserButton());
return;
}
} else {
if (!isModelExists(llamaModelPreferencesForm.getSelectedModel())) {
OverlayUtils.showBalloon(
"Model is not downloaded",
CodeGPTBundle.get("settingsConfigurable.service.llama.overlay.modelNotDownloaded.text"),
MessageType.ERROR,
llamaModelPreferencesForm.getHuggingFaceModelComboBox());
return;
Expand All @@ -66,15 +69,15 @@ public LlamaServiceSelectionForm() {

if (llamaServerAgent.isServerRunning()) {
setFormEnabled(true);
serverButton.setText("Start Server");
serverButton.setText(CodeGPTBundle.get("settingsConfigurable.service.llama.startServer.label"));
serverButton.setIcon(Actions.Execute);
serverProgressPanel.updateText("Stopping a server...");
serverProgressPanel.updateText(CodeGPTBundle.get("settingsConfigurable.service.llama.progress.stoppingServer"));
llamaServerAgent.stopAgent();
} else {
setFormEnabled(false);
serverButton.setText("Stop Server");
serverButton.setText(CodeGPTBundle.get("settingsConfigurable.service.llama.stopServer.label"));
serverButton.setIcon(Actions.Suspend);
serverProgressPanel.startProgress("Starting a server...");
serverProgressPanel.startProgress(CodeGPTBundle.get("settingsConfigurable.service.llama.progress.startingServer"));

// TODO: Move to LlamaModelPreferencesForm
var modelPath = llamaModelPreferencesForm.isUseCustomLlamaModel() ?
Expand All @@ -96,13 +99,13 @@ public LlamaServiceSelectionForm() {
setFormEnabled(!llamaServerAgent.isServerRunning());
setLayout(new BorderLayout());
add(FormBuilder.createFormBuilder()
.addComponent(new TitledSeparator("Model Preferences"))
.addComponent(new TitledSeparator(CodeGPTBundle.get("settingsConfigurable.service.llama.modelPreferences.title")))
.addComponent(withEmptyLeftBorder(llamaModelPreferencesForm.getForm()))
.addComponent(new TitledSeparator("Server Preferences"))
.addComponent(new TitledSeparator(CodeGPTBundle.get("settingsConfigurable.service.llama.serverPreferences.title")))
.addComponent(withEmptyLeftBorder(FormBuilder.createFormBuilder()
.addLabeledComponent("Context size:", maxTokensField)
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.llama.contextSize.label"), maxTokensField)
.addComponentToRightColumn(contextSizeHelpText)
.addLabeledComponent("Port:", JBUI.Panels.simplePanel()
.addLabeledComponent(CodeGPTBundle.get("settingsConfigurable.service.llama.port.label"), JBUI.Panels.simplePanel()
.addToLeft(portField)
.addToRight(serverButton))
.getPanel()))
Expand Down

This file was deleted.

Loading

0 comments on commit e41fa85

Please sign in to comment.