mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-19 16:28:46 +00:00
Replace last message on response regeneration #51
This commit is contained in:
parent
ad3196afb1
commit
1b312da9ab
4 changed files with 37 additions and 13 deletions
|
|
@ -33,11 +33,19 @@ public class ToolWindowService implements LafManagerListener {
|
|||
return chatToolWindow;
|
||||
}
|
||||
|
||||
public void startRequest(String prompt, SyntaxTextArea textArea, Project project) {
|
||||
public void startRequest(String prompt, SyntaxTextArea textArea, Project project, boolean isRetry) {
|
||||
var conversationsState = ConversationsState.getInstance();
|
||||
var currentConversation = ConversationsState.getCurrentConversation();
|
||||
var conversation = currentConversation == null ? conversationsState.startConversation() : currentConversation;
|
||||
var conversationMessage = new Message(prompt);
|
||||
|
||||
Message conversationMessage;
|
||||
if (isRetry) {
|
||||
var messages = conversation.getMessages();
|
||||
conversationMessage = messages.get(messages.size() - 1);
|
||||
conversationMessage.setResponse("");
|
||||
} else {
|
||||
conversationMessage = new Message(prompt);
|
||||
}
|
||||
|
||||
new SwingWorker<Void, String>() {
|
||||
protected Void doInBackground() {
|
||||
|
|
|
|||
|
|
@ -129,16 +129,28 @@ public class ChatGptToolWindow {
|
|||
}
|
||||
|
||||
public void sendMessage(String prompt, Project project) {
|
||||
addIconLabel(Icons.DefaultImageIcon, "ChatGPT");
|
||||
sendMessage(prompt, project, false);
|
||||
}
|
||||
|
||||
public void sendMessage(String prompt, Project project, boolean isRetry) {
|
||||
if (!isRetry) {
|
||||
addIconLabel(Icons.DefaultImageIcon, "ChatGPT");
|
||||
}
|
||||
|
||||
var settings = SettingsState.getInstance();
|
||||
if (settings.apiKey.isEmpty()) {
|
||||
notifyMissingCredential(project, "API key not provided.");
|
||||
} else {
|
||||
var textArea = new SyntaxTextArea(true, true, SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
|
||||
addTextArea(textArea);
|
||||
SyntaxTextArea textArea;
|
||||
if (isRetry) {
|
||||
textArea = textAreas.get(textAreas.size() - 1);
|
||||
textArea.clear();
|
||||
} else {
|
||||
textArea = new SyntaxTextArea(true, true, SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
|
||||
addTextArea(textArea);
|
||||
}
|
||||
project.getService(ToolWindowService.class)
|
||||
.startRequest(prompt, textArea, project);
|
||||
.startRequest(prompt, textArea, project, isRetry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -177,11 +189,11 @@ public class ChatGptToolWindow {
|
|||
|
||||
public void stopGenerating(String prompt, SyntaxTextArea textArea, Project project) {
|
||||
generateButton.setMode(GenerateButton.Mode.REFRESH, () -> {
|
||||
sendMessage(prompt, project);
|
||||
sendMessage(prompt, project, true);
|
||||
scrollToBottom();
|
||||
});
|
||||
textArea.displayCopyButton();
|
||||
textArea.hideCaret();
|
||||
textArea.getCaret().setVisible(false);
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,6 @@ public class SyntaxTextArea extends RSyntaxTextArea {
|
|||
cb.install(this);
|
||||
}
|
||||
|
||||
public void hideCaret() {
|
||||
getCaret().setVisible(false);
|
||||
}
|
||||
|
||||
public void changeStyleViaThemeXml() {
|
||||
var baseThemePath = "/org/fife/ui/rsyntaxtextarea/themes/";
|
||||
try {
|
||||
|
|
@ -44,6 +40,14 @@ public class SyntaxTextArea extends RSyntaxTextArea {
|
|||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
removeAll();
|
||||
setText("");
|
||||
getCaret().setVisible(true);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void setStyles(boolean isReadOnly, boolean withBlockCaret, String syntax) {
|
||||
setMargin(JBUI.insets(5));
|
||||
setAntiAliasingEnabled(true);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@
|
|||
</projectListeners>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<postStartupActivity implementation="ee.carlrobert.codegpt.PluginStartupActivity" />
|
||||
<postStartupActivity implementation="ee.carlrobert.codegpt.PluginStartupActivity"/>
|
||||
<applicationConfigurable id="settings.codegpt" parentId="tools" displayName="CodeGPT"
|
||||
instance="ee.carlrobert.codegpt.settings.SettingsConfigurable"/>
|
||||
<applicationConfigurable id="settings.codegpt.configuration" parentId="settings.codegpt" displayName="Configuration"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue