mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-12 05:51:28 +00:00
adds: configuration for the commit-message system prompt (#304)
* adds: configuration for the commit-message system prompt this will remove the default file and move it to the code to be overwritten if the user chooses to modify the prompt. * fix: checkstyle --------- Co-authored-by: Carl-Robert Linnupuu <carlrobertoh@gmail.com>
This commit is contained in:
parent
c36d4dd566
commit
c214b59f55
7 changed files with 59 additions and 5 deletions
|
|
@ -2,7 +2,6 @@ package ee.carlrobert.codegpt.actions;
|
|||
|
||||
import static com.intellij.openapi.ui.Messages.OK;
|
||||
import static com.intellij.util.ObjectUtils.tryCast;
|
||||
import static ee.carlrobert.codegpt.util.file.FileUtil.getResourceContent;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
|
|
@ -26,6 +25,7 @@ import ee.carlrobert.codegpt.EncodingManager;
|
|||
import ee.carlrobert.codegpt.Icons;
|
||||
import ee.carlrobert.codegpt.completions.CompletionClientProvider;
|
||||
import ee.carlrobert.codegpt.credentials.OpenAICredentialsManager;
|
||||
import ee.carlrobert.codegpt.settings.configuration.ConfigurationState;
|
||||
import ee.carlrobert.codegpt.settings.state.OpenAISettingsState;
|
||||
import ee.carlrobert.codegpt.util.OverlayUtil;
|
||||
import ee.carlrobert.llm.client.openai.completion.ErrorDetails;
|
||||
|
|
@ -85,7 +85,7 @@ public class GenerateGitCommitMessageAction extends AnAction {
|
|||
CompletionClientProvider.getOpenAIClient().getChatCompletion(
|
||||
new OpenAIChatCompletionRequest.Builder(List.of(
|
||||
new OpenAIChatCompletionMessage("system",
|
||||
getResourceContent("/prompts/git-message.txt")),
|
||||
ConfigurationState.getInstance().getCommitMessagePrompt()),
|
||||
new OpenAIChatCompletionMessage("user", gitDiff)))
|
||||
.setModel(OpenAISettingsState.getInstance().getModel())
|
||||
.build(),
|
||||
|
|
|
|||
|
|
@ -61,6 +61,11 @@ public class CompletionRequestProvider {
|
|||
+ "the output of running the code as well as an integrated terminal.\n"
|
||||
+ "You can only give one reply for each conversation turn.";
|
||||
|
||||
public static final String COMPLETION_COMMIT_MESSAGE_PROMPT =
|
||||
"Write a short and descriptive git commit message for the following git diff.\n"
|
||||
+ "Use imperative mood, present tense, active voice and verbs.\n"
|
||||
+ "Your entire response will be passed directly into git commit.";
|
||||
|
||||
private final EncodingManager encodingManager = EncodingManager.getInstance();
|
||||
private final EmbeddingsService embeddingsService;
|
||||
private final Conversation conversation;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.intellij.ui.TitledSeparator;
|
|||
import com.intellij.ui.ToolbarDecorator;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBTextArea;
|
||||
import com.intellij.ui.components.JBTextField;
|
||||
import com.intellij.ui.components.fields.IntegerField;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
|
|
@ -46,6 +47,7 @@ public class ConfigurationComponent {
|
|||
private final JBCheckBox methodNameGenerationCheckBox;
|
||||
private final JBCheckBox autoFormattingCheckBox;
|
||||
private final JTextArea systemPromptTextArea;
|
||||
private final JTextArea commitMessagePromptTextArea;
|
||||
private final IntegerField maxTokensField;
|
||||
private final JBTextField temperatureField;
|
||||
|
||||
|
|
@ -100,6 +102,10 @@ public class ConfigurationComponent {
|
|||
systemPromptTextArea.setColumns(60);
|
||||
systemPromptTextArea.setRows(3);
|
||||
|
||||
commitMessagePromptTextArea = new JBTextArea(configuration.getCommitMessagePrompt(), 3, 60);
|
||||
commitMessagePromptTextArea.setLineWrap(true);
|
||||
commitMessagePromptTextArea.setBorder(JBUI.Borders.empty(8, 4));
|
||||
|
||||
checkForPluginUpdatesCheckBox = new JBCheckBox(
|
||||
CodeGPTBundle.get("configurationConfigurable.checkForPluginUpdates.label"),
|
||||
configuration.isCheckForPluginUpdates());
|
||||
|
|
@ -125,6 +131,10 @@ public class ConfigurationComponent {
|
|||
CodeGPTBundle.get("configurationConfigurable.section.assistant.title")))
|
||||
.addComponent(createAssistantConfigurationForm())
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.addComponent(new TitledSeparator(
|
||||
CodeGPTBundle.get("configurationConfigurable.section.commitMessage.title")))
|
||||
.addComponent(createCommitMessageConfigurationForm())
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
|
|
@ -200,6 +210,23 @@ public class ConfigurationComponent {
|
|||
return form;
|
||||
}
|
||||
|
||||
private JPanel createCommitMessageConfigurationForm() {
|
||||
var formBuilder = FormBuilder.createFormBuilder();
|
||||
addAssistantFormLabeledComponent(
|
||||
formBuilder,
|
||||
"configurationConfigurable.section.commitMessage.systemPromptField.label",
|
||||
"configurationConfigurable.section.commitMessage.systemPromptField.comment",
|
||||
JBUI.Panels
|
||||
.simplePanel(commitMessagePromptTextArea)
|
||||
.withBorder(JBUI.Borders.customLine(
|
||||
JBUI.CurrentTheme.CustomFrameDecorations.separatorForeground())));
|
||||
formBuilder.addVerticalGap(8);
|
||||
|
||||
var form = formBuilder.getPanel();
|
||||
form.setBorder(JBUI.Borders.emptyLeft(16));
|
||||
return form;
|
||||
}
|
||||
|
||||
private ComponentValidator createInputValidator(
|
||||
Disposable parentDisposable,
|
||||
JBTextField component) {
|
||||
|
|
@ -245,6 +272,14 @@ public class ConfigurationComponent {
|
|||
return systemPromptTextArea.getText();
|
||||
}
|
||||
|
||||
public void setCommitMessagePrompt(String commitMessagePrompt) {
|
||||
commitMessagePromptTextArea.setText(commitMessagePrompt);
|
||||
}
|
||||
|
||||
public String getCommitMessagePrompt() {
|
||||
return commitMessagePromptTextArea.getText();
|
||||
}
|
||||
|
||||
public double getTemperature() {
|
||||
return Double.parseDouble(temperatureField.getText());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ public class ConfigurationConfigurable implements Configurable {
|
|||
|| configurationComponent.getMaxTokens() != configuration.getMaxTokens()
|
||||
|| configurationComponent.getTemperature() != configuration.getTemperature()
|
||||
|| !configurationComponent.getSystemPrompt().equals(configuration.getSystemPrompt())
|
||||
|| !configurationComponent.getCommitMessagePrompt()
|
||||
.equals(configuration.getCommitMessagePrompt())
|
||||
|| configurationComponent.isCheckForPluginUpdates()
|
||||
!= configuration.isCheckForPluginUpdates()
|
||||
|| configurationComponent.isCreateNewChatOnEachAction()
|
||||
|
|
@ -54,6 +56,7 @@ public class ConfigurationConfigurable implements Configurable {
|
|||
configuration.setMaxTokens(configurationComponent.getMaxTokens());
|
||||
configuration.setTemperature(configurationComponent.getTemperature());
|
||||
configuration.setSystemPrompt(configurationComponent.getSystemPrompt());
|
||||
configuration.setCommitMessagePrompt(configurationComponent.getCommitMessagePrompt());
|
||||
configuration.setCheckForPluginUpdates(configurationComponent.isCheckForPluginUpdates());
|
||||
configuration.setCreateNewChatOnEachAction(
|
||||
configurationComponent.isCreateNewChatOnEachAction());
|
||||
|
|
@ -70,6 +73,7 @@ public class ConfigurationConfigurable implements Configurable {
|
|||
configurationComponent.setMaxTokens(configuration.getMaxTokens());
|
||||
configurationComponent.setTemperature(configuration.getTemperature());
|
||||
configurationComponent.setSystemPrompt(configuration.getSystemPrompt());
|
||||
configurationComponent.setCommitMessagePrompt(configuration.getCommitMessagePrompt());
|
||||
configurationComponent.setCheckForPluginUpdates(configuration.isCheckForPluginUpdates());
|
||||
configurationComponent.setCreateNewChatOnEachAction(
|
||||
configuration.isCreateNewChatOnEachAction());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package ee.carlrobert.codegpt.settings.configuration;
|
||||
|
||||
import static ee.carlrobert.codegpt.completions.CompletionRequestProvider.COMPLETION_COMMIT_MESSAGE_PROMPT;
|
||||
import static ee.carlrobert.codegpt.completions.CompletionRequestProvider.COMPLETION_SYSTEM_PROMPT;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
|
|
@ -18,6 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
public class ConfigurationState implements PersistentStateComponent<ConfigurationState> {
|
||||
|
||||
private String systemPrompt = COMPLETION_SYSTEM_PROMPT;
|
||||
private String commitMessagePrompt = COMPLETION_COMMIT_MESSAGE_PROMPT;
|
||||
private int maxTokens = 1000;
|
||||
private double temperature = 0.1;
|
||||
private boolean checkForPluginUpdates = true;
|
||||
|
|
@ -46,10 +48,18 @@ public class ConfigurationState implements PersistentStateComponent<Configuratio
|
|||
return systemPrompt;
|
||||
}
|
||||
|
||||
public String getCommitMessagePrompt() {
|
||||
return commitMessagePrompt;
|
||||
}
|
||||
|
||||
public void setSystemPrompt(String systemPrompt) {
|
||||
this.systemPrompt = systemPrompt;
|
||||
}
|
||||
|
||||
public void setCommitMessagePrompt(String commitMessagePrompt) {
|
||||
this.commitMessagePrompt = commitMessagePrompt;
|
||||
}
|
||||
|
||||
public int getMaxTokens() {
|
||||
return maxTokens;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue