refactor: remove max_tokens configuration and other minor fixes

This commit is contained in:
Carl-Robert Linnupuu 2024-05-13 15:32:20 +03:00
parent 0b21652c04
commit 014f26f802
23 changed files with 219 additions and 259 deletions

View file

@ -47,6 +47,7 @@ public class ConfigurationComponent {
private final JBCheckBox openNewTabCheckBox;
private final JBCheckBox methodNameGenerationCheckBox;
private final JBCheckBox autoFormattingCheckBox;
private final JBCheckBox autocompletionPostProcessingCheckBox;
private final JTextArea systemPromptTextArea;
private final JTextArea commitMessagePromptTextArea;
private final IntegerField maxTokensField;
@ -123,6 +124,10 @@ public class ConfigurationComponent {
autoFormattingCheckBox = new JBCheckBox(
CodeGPTBundle.get("configurationConfigurable.autoFormatting.label"),
configuration.isAutoFormattingEnabled());
autocompletionPostProcessingCheckBox = new JBCheckBox(
CodeGPTBundle.get("configurationConfigurable.autocompletionPostProcessing.label"),
configuration.isAutocompletionPostProcessingEnabled()
);
mainPanel = FormBuilder.createFormBuilder()
.addComponent(tablePanel)
@ -132,6 +137,7 @@ public class ConfigurationComponent {
.addComponent(openNewTabCheckBox)
.addComponent(methodNameGenerationCheckBox)
.addComponent(autoFormattingCheckBox)
.addComponent(autocompletionPostProcessingCheckBox)
.addVerticalGap(4)
.addComponent(new TitledSeparator(
CodeGPTBundle.get("configurationConfigurable.section.assistant.title")))
@ -159,6 +165,7 @@ public class ConfigurationComponent {
state.setCreateNewChatOnEachAction(openNewTabCheckBox.isSelected());
state.setMethodNameGenerationEnabled(methodNameGenerationCheckBox.isSelected());
state.setAutoFormattingEnabled(autoFormattingCheckBox.isSelected());
state.setAutocompletionPostProcessingEnabled(autocompletionPostProcessingCheckBox.isSelected());
return state;
}
@ -174,6 +181,8 @@ public class ConfigurationComponent {
openNewTabCheckBox.setSelected(configuration.isCreateNewChatOnEachAction());
methodNameGenerationCheckBox.setSelected(configuration.isMethodNameGenerationEnabled());
autoFormattingCheckBox.setSelected(configuration.isAutoFormattingEnabled());
autocompletionPostProcessingCheckBox.setSelected(
configuration.isAutocompletionPostProcessingEnabled());
}
private Map<String, String> getTableData() {

View file

@ -20,6 +20,7 @@ public class ConfigurationState {
private boolean methodNameGenerationEnabled = true;
private boolean captureCompileErrors = true;
private boolean autoFormattingEnabled = true;
private boolean autocompletionPostProcessingEnabled = true;
private Map<String, String> tableData = EditorActionsUtil.DEFAULT_ACTIONS;
public String getSystemPrompt() {
@ -118,6 +119,14 @@ public class ConfigurationState {
this.autoFormattingEnabled = autoFormattingEnabled;
}
public boolean isAutocompletionPostProcessingEnabled() {
return autocompletionPostProcessingEnabled;
}
public void setAutocompletionPostProcessingEnabled(boolean autocompletionPostProcessingEnabled) {
this.autocompletionPostProcessingEnabled = autocompletionPostProcessingEnabled;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -135,6 +144,7 @@ public class ConfigurationState {
&& methodNameGenerationEnabled == that.methodNameGenerationEnabled
&& captureCompileErrors == that.captureCompileErrors
&& autoFormattingEnabled == that.autoFormattingEnabled
&& autocompletionPostProcessingEnabled == that.autocompletionPostProcessingEnabled
&& Objects.equals(systemPrompt, that.systemPrompt)
&& Objects.equals(commitMessagePrompt, that.commitMessagePrompt)
&& Objects.equals(tableData, that.tableData);
@ -145,6 +155,6 @@ public class ConfigurationState {
return Objects.hash(systemPrompt, commitMessagePrompt, maxTokens, temperature,
checkForPluginUpdates, checkForNewScreenshots, createNewChatOnEachAction,
ignoreGitCommitTokenLimit, methodNameGenerationEnabled, captureCompileErrors,
autoFormattingEnabled, tableData);
autoFormattingEnabled, autocompletionPostProcessingEnabled, tableData);
}
}

View file

@ -29,7 +29,6 @@ public class LlamaSettingsState {
private double minP = 0.05;
private double repeatPenalty = 1.1;
private boolean codeCompletionsEnabled = true;
private int codeCompletionMaxTokens = 128;
public boolean isUseCustomModel() {
return useCustomModel;
@ -187,14 +186,6 @@ public class LlamaSettingsState {
this.codeCompletionsEnabled = codeCompletionsEnabled;
}
public int getCodeCompletionMaxTokens() {
return codeCompletionMaxTokens;
}
public void setCodeCompletionMaxTokens(int codeCompletionMaxTokens) {
this.codeCompletionMaxTokens = codeCompletionMaxTokens;
}
private static Integer getRandomAvailablePortOrDefault() {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
@ -230,8 +221,7 @@ public class LlamaSettingsState {
&& Objects.equals(serverPort, that.serverPort)
&& Objects.equals(additionalParameters, that.additionalParameters)
&& Objects.equals(additionalBuildParameters, that.additionalBuildParameters)
&& codeCompletionsEnabled == that.codeCompletionsEnabled
&& codeCompletionMaxTokens == that.codeCompletionMaxTokens;
&& codeCompletionsEnabled == that.codeCompletionsEnabled;
}
@Override
@ -240,6 +230,6 @@ public class LlamaSettingsState {
localModelPromptTemplate, remoteModelPromptTemplate, localModelInfillPromptTemplate,
remoteModelInfillPromptTemplate, baseHost, serverPort, contextSize, threads,
additionalParameters, additionalBuildParameters, topK, topP, minP, repeatPenalty,
codeCompletionsEnabled, codeCompletionMaxTokens);
codeCompletionsEnabled);
}
}

View file

@ -22,7 +22,6 @@ public class LlamaSettingsForm extends JPanel {
llamaRequestPreferencesForm = new LlamaRequestPreferencesForm(settings);
codeCompletionConfigurationForm = new CodeCompletionConfigurationForm(
settings.isCodeCompletionsEnabled(),
settings.getCodeCompletionMaxTokens(),
null);
init();
}
@ -50,9 +49,7 @@ public class LlamaSettingsForm extends JPanel {
state.setUseCustomModel(modelPreferencesForm.isUseCustomLlamaModel());
state.setLocalModelPromptTemplate(modelPreferencesForm.getPromptTemplate());
state.setLocalModelInfillPromptTemplate(modelPreferencesForm.getInfillPromptTemplate());
state.setCodeCompletionsEnabled(codeCompletionConfigurationForm.isCodeCompletionsEnabled());
state.setCodeCompletionMaxTokens(codeCompletionConfigurationForm.getMaxTokens());
return state;
}
@ -61,7 +58,6 @@ public class LlamaSettingsForm extends JPanel {
llamaServerPreferencesForm.resetForm(state);
llamaRequestPreferencesForm.resetForm(state);
codeCompletionConfigurationForm.setCodeCompletionsEnabled(state.isCodeCompletionsEnabled());
codeCompletionConfigurationForm.setMaxTokens(state.getCodeCompletionMaxTokens());
}
public LlamaServerPreferencesForm getLlamaServerPreferencesForm() {

View file

@ -1,20 +1,17 @@
package ee.carlrobert.codegpt.settings.service.openai;
import static ee.carlrobert.codegpt.credentials.CredentialsStore.CredentialKey.OPENAI_API_KEY;
import static ee.carlrobert.codegpt.ui.UIUtil.withEmptyLeftBorder;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.ui.EnumComboBoxModel;
import com.intellij.ui.TitledSeparator;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBPasswordField;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.UI;
import ee.carlrobert.codegpt.CodeGPTBundle;
import ee.carlrobert.codegpt.credentials.CredentialsStore;
import ee.carlrobert.codegpt.credentials.CredentialsStore.CredentialKey;
import ee.carlrobert.codegpt.settings.service.CodeCompletionConfigurationForm;
import ee.carlrobert.codegpt.ui.UIUtil;
import ee.carlrobert.llm.client.openai.completion.OpenAIChatCompletionModel;
import javax.swing.JPanel;
@ -26,7 +23,7 @@ public class OpenAISettingsForm {
private final JBPasswordField apiKeyField;
private final JBTextField organizationField;
private final ComboBox<OpenAIChatCompletionModel> completionModelComboBox;
private final CodeCompletionConfigurationForm codeCompletionConfigurationForm;
private final JBCheckBox codeCompletionsEnabledCheckBox;
public OpenAISettingsForm(OpenAISettingsState settings) {
apiKeyField = new JBPasswordField();
@ -40,34 +37,28 @@ public class OpenAISettingsForm {
new EnumComboBoxModel<>(OpenAIChatCompletionModel.class));
completionModelComboBox.setSelectedItem(
OpenAIChatCompletionModel.findByCode(settings.getModel()));
codeCompletionConfigurationForm = new CodeCompletionConfigurationForm(
settings.isCodeCompletionsEnabled(),
settings.getCodeCompletionMaxTokens(),
null);
codeCompletionsEnabledCheckBox = new JBCheckBox(
CodeGPTBundle.get("codeCompletionsForm.enableFeatureText"),
settings.isCodeCompletionsEnabled());
}
public JPanel getForm() {
var configurationGrid = UI.PanelFactory.grid()
.add(UI.PanelFactory.panel(apiKeyField)
.withLabel(CodeGPTBundle.get("settingsConfigurable.shared.apiKey.label"))
.resizeX(false)
.withComment(CodeGPTBundle.get("settingsConfigurable.service.openai.apiKey.comment"))
.withCommentHyperlinkListener(UIUtil::handleHyperlinkClicked))
.add(UI.PanelFactory.panel(organizationField)
.withLabel(CodeGPTBundle.get("settingsConfigurable.service.openai.organization.label"))
.resizeX(false)
.withComment(CodeGPTBundle.get(
"settingsConfigurable.section.openai.organization.comment")))
.add(UI.PanelFactory.panel(completionModelComboBox)
.withLabel(CodeGPTBundle.get("settingsConfigurable.shared.model.label"))
.resizeX(false))
.createPanel();
return FormBuilder.createFormBuilder()
.addComponent(new TitledSeparator(CodeGPTBundle.get("shared.configuration")))
.addComponent(withEmptyLeftBorder(configurationGrid))
.addComponent(new TitledSeparator(CodeGPTBundle.get("shared.codeCompletions")))
.addComponent(withEmptyLeftBorder(codeCompletionConfigurationForm.getForm()))
.addLabeledComponent(
CodeGPTBundle.get("settingsConfigurable.shared.apiKey.label"), apiKeyField)
.addComponentToRightColumn(
UIUtil.createComment("settingsConfigurable.service.openai.apiKey.comment")
)
.addLabeledComponent(
CodeGPTBundle.get("settingsConfigurable.service.openai.organization.label"),
organizationField)
.addComponentToRightColumn(
UIUtil.createComment("settingsConfigurable.section.openai.organization.comment")
)
.addLabeledComponent(
CodeGPTBundle.get("settingsConfigurable.shared.model.label"), completionModelComboBox)
.addVerticalGap(4)
.addComponent(codeCompletionsEnabledCheckBox)
.addComponentFillVertically(new JPanel(), 0)
.getPanel();
}
@ -87,8 +78,7 @@ public class OpenAISettingsForm {
var state = new OpenAISettingsState();
state.setModel(getModel());
state.setOrganization(organizationField.getText());
state.setCodeCompletionsEnabled(codeCompletionConfigurationForm.isCodeCompletionsEnabled());
state.setCodeCompletionMaxTokens(codeCompletionConfigurationForm.getMaxTokens());
state.setCodeCompletionsEnabled(codeCompletionsEnabledCheckBox.isSelected());
return state;
}
@ -98,7 +88,6 @@ public class OpenAISettingsForm {
completionModelComboBox.setSelectedItem(
OpenAIChatCompletionModel.findByCode(state.getModel()));
organizationField.setText(state.getOrganization());
codeCompletionConfigurationForm.setCodeCompletionsEnabled(state.isCodeCompletionsEnabled());
codeCompletionConfigurationForm.setMaxTokens(state.getCodeCompletionMaxTokens());
codeCompletionsEnabledCheckBox.setSelected(state.isCodeCompletionsEnabled());
}
}

View file

@ -8,7 +8,6 @@ public class OpenAISettingsState {
private String organization = "";
private String model = OpenAIChatCompletionModel.GPT_3_5_0125_16k.getCode();
private boolean codeCompletionsEnabled = true;
private int codeCompletionMaxTokens = 128;
public String getOrganization() {
return organization;
@ -34,14 +33,6 @@ public class OpenAISettingsState {
this.codeCompletionsEnabled = codeCompletionsEnabled;
}
public int getCodeCompletionMaxTokens() {
return codeCompletionMaxTokens;
}
public void setCodeCompletionMaxTokens(int codeCompletionMaxTokens) {
this.codeCompletionMaxTokens = codeCompletionMaxTokens;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -53,12 +44,11 @@ public class OpenAISettingsState {
OpenAISettingsState that = (OpenAISettingsState) o;
return Objects.equals(organization, that.organization)
&& Objects.equals(model, that.model)
&& codeCompletionsEnabled == that.codeCompletionsEnabled
&& codeCompletionMaxTokens == that.codeCompletionMaxTokens;
&& codeCompletionsEnabled == that.codeCompletionsEnabled;
}
@Override
public int hashCode() {
return Objects.hash(organization, model, codeCompletionsEnabled, codeCompletionMaxTokens);
return Objects.hash(organization, model, codeCompletionsEnabled);
}
}

View file

@ -5,7 +5,6 @@ import static ee.carlrobert.codegpt.settings.service.ServiceType.CUSTOM_OPENAI;
import static ee.carlrobert.codegpt.settings.service.ServiceType.OLLAMA;
import static ee.carlrobert.codegpt.settings.service.ServiceType.OPENAI;
import static ee.carlrobert.codegpt.settings.service.ServiceType.YOU;
import static ee.carlrobert.llm.client.codegpt.CodeGPTAvailableModels.AVAILABLE_CHAT_MODELS;
import static java.lang.String.format;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
@ -25,13 +24,14 @@ import ee.carlrobert.codegpt.credentials.CredentialsStore;
import ee.carlrobert.codegpt.credentials.CredentialsStore.CredentialKey;
import ee.carlrobert.codegpt.settings.GeneralSettings;
import ee.carlrobert.codegpt.settings.service.ServiceType;
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTAvailableModels;
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTModel;
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTServiceSettings;
import ee.carlrobert.codegpt.settings.service.custom.CustomServiceSettings;
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings;
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettings;
import ee.carlrobert.codegpt.settings.service.openai.OpenAISettings;
import ee.carlrobert.codegpt.settings.service.you.YouSettings;
import ee.carlrobert.llm.client.codegpt.CodeGPTModel;
import ee.carlrobert.llm.client.openai.completion.OpenAIChatCompletionModel;
import ee.carlrobert.llm.client.you.completion.YouCompletionCustomModel;
import ee.carlrobert.llm.client.you.completion.YouCompletionMode;
@ -67,9 +67,9 @@ public class ModelComboBoxAction extends ComboBoxAction {
private AnAction[] getCodeGPTModelActions(Presentation presentation) {
var apiKey = CredentialsStore.getCredential(CredentialKey.CODEGPT_API_KEY);
return AVAILABLE_CHAT_MODELS.stream()
return CodeGPTAvailableModels.getCHAT_MODELS().stream()
.map(model -> {
var enabled = "codellama/CodeLlama-13b-Instruct-hf".equals(model.getCode())
var enabled = "meta-llama/Llama-3-8b-chat-hf".equals(model.getCode())
|| (apiKey != null && !apiKey.isEmpty());
return createCodeGPTModelAction(model, enabled, presentation);
})
@ -174,7 +174,7 @@ public class ModelComboBoxAction extends ComboBoxAction {
.getState()
.getChatCompletionSettings()
.getModel();
var modelName = AVAILABLE_CHAT_MODELS.stream()
var modelName = CodeGPTAvailableModels.getCHAT_MODELS().stream()
.filter(it -> it.getCode().equals(model))
.map(CodeGPTModel::getName)
.findFirst().orElse("Unknown");