mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-03 06:00:57 +00:00
1.4.4 - Replace model on conversation change, start new conversation on model change
This commit is contained in:
parent
483abe146b
commit
63020ba49d
13 changed files with 89 additions and 101 deletions
|
|
@ -37,6 +37,7 @@ import javax.swing.JPanel;
|
|||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -67,53 +68,49 @@ public class ChatGptToolWindow {
|
|||
}
|
||||
|
||||
public void displayUserMessage(String userMessage) {
|
||||
if (isLandingViewVisible || ConversationsState.getCurrentConversation() == null) {
|
||||
clearWindow();
|
||||
}
|
||||
|
||||
addIconLabel(AllIcons.General.User, "User:");
|
||||
scrollablePanel.add(createTextArea(userMessage));
|
||||
scrollablePanel.validate();
|
||||
scrollablePanel.revalidate();
|
||||
scrollablePanel.repaint();
|
||||
}
|
||||
|
||||
public void displayLandingView() {
|
||||
isLandingViewVisible = true;
|
||||
clearWindow();
|
||||
if (!isLandingViewVisible) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
clearWindow();
|
||||
isLandingViewVisible = true;
|
||||
|
||||
var landingView = new LandingView();
|
||||
scrollablePanel.add(landingView.createImageIconPanel());
|
||||
addSpacing(16);
|
||||
landingView.getQuestionPanels().forEach(panel -> {
|
||||
scrollablePanel.add(panel);
|
||||
addSpacing(16);
|
||||
});
|
||||
|
||||
scrollablePanel.validate();
|
||||
scrollablePanel.repaint();
|
||||
addSpacing(16);
|
||||
var landingView = new LandingView();
|
||||
scrollablePanel.add(landingView.createImageIconPanel());
|
||||
addSpacing(16);
|
||||
landingView.getQuestionPanels().forEach(panel -> {
|
||||
scrollablePanel.add(panel);
|
||||
addSpacing(16);
|
||||
});
|
||||
scrollablePanel.revalidate();
|
||||
scrollablePanel.repaint();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void displayConversation(Conversation conversation) {
|
||||
clearWindow();
|
||||
|
||||
conversation.getMessages().forEach(message -> {
|
||||
displayUserMessage(message.getPrompt());
|
||||
|
||||
addIconLabel(Icons.DefaultImageIcon, "ChatGPT:");
|
||||
var textArea = new SyntaxTextArea(true, true, SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
|
||||
var textArea = new SyntaxTextArea(true, false, SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
|
||||
textArea.setText(message.getResponse());
|
||||
textArea.displayCopyButton();
|
||||
textArea.hideCaret();
|
||||
scrollablePanel.add(textArea);
|
||||
textAreas.add(textArea);
|
||||
});
|
||||
|
||||
scrollToBottom();
|
||||
scrollablePanel.validate();
|
||||
scrollablePanel.revalidate();
|
||||
scrollablePanel.repaint();
|
||||
}
|
||||
|
||||
public void displayResponse(String prompt) {
|
||||
public void sendMessage(String prompt, Project project) {
|
||||
addIconLabel(Icons.DefaultImageIcon, "ChatGPT:");
|
||||
|
||||
var settings = SettingsState.getInstance();
|
||||
|
|
@ -124,14 +121,16 @@ public class ChatGptToolWindow {
|
|||
} else {
|
||||
var textArea = new SyntaxTextArea(true, true, SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
|
||||
addTextArea(textArea);
|
||||
project.getService(ToolWindowService.class)
|
||||
.startRequest(prompt, textArea, project);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearWindow() {
|
||||
isLandingViewVisible = false;
|
||||
generateButton.setVisible(false);
|
||||
scrollablePanel.removeAll();
|
||||
textAreas.clear();
|
||||
scrollablePanel.removeAll();
|
||||
}
|
||||
|
||||
public void addSpacing(int height) {
|
||||
|
|
@ -160,8 +159,11 @@ public class ChatGptToolWindow {
|
|||
generateButton.setMode(GenerateButton.Mode.STOP, onClick);
|
||||
}
|
||||
|
||||
public void stopGenerating(SyntaxTextArea textArea, Runnable onRefresh) {
|
||||
generateButton.setMode(GenerateButton.Mode.REFRESH, onRefresh);
|
||||
public void stopGenerating(String prompt, SyntaxTextArea textArea, Project project) {
|
||||
generateButton.setMode(GenerateButton.Mode.REFRESH, () -> {
|
||||
sendMessage(prompt, project);
|
||||
scrollToBottom();
|
||||
});
|
||||
textArea.displayCopyButton();
|
||||
textArea.hideCaret();
|
||||
scrollToBottom();
|
||||
|
|
@ -184,15 +186,15 @@ public class ChatGptToolWindow {
|
|||
|
||||
private void handleSubmit() {
|
||||
var searchText = textArea.getText();
|
||||
|
||||
if (isLandingViewVisible || ConversationsState.getCurrentConversation() == null) {
|
||||
clearWindow();
|
||||
}
|
||||
displayUserMessage(searchText);
|
||||
|
||||
displayResponse()
|
||||
project.getService(ToolWindowService.class).sendMessage(searchText, project);
|
||||
|
||||
|
||||
sendMessage(searchText, project);
|
||||
textArea.setText("");
|
||||
scrollToBottom();
|
||||
scrollablePanel.revalidate();
|
||||
scrollablePanel.repaint();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
|
|
@ -208,16 +210,11 @@ public class ChatGptToolWindow {
|
|||
textAreaScrollPane.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createMatteBorder(1, 0, 0, 0, JBColor.border()),
|
||||
BorderFactory.createEmptyBorder(0, 5, 0, 10)));
|
||||
textAreaScrollPane.setViewportView(textArea);
|
||||
|
||||
textArea = new TextArea(this::handleSubmit, textAreaScrollPane);
|
||||
|
||||
textAreaScrollPane.setViewportView(textArea);
|
||||
scrollablePanel = new ScrollablePanel();
|
||||
scrollablePanel.setLayout(new BoxLayout(scrollablePanel, BoxLayout.Y_AXIS));
|
||||
|
||||
scrollPane = new ScrollPane(scrollablePanel);
|
||||
generateButton = new GenerateButton();
|
||||
|
||||
displayLandingView();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
package ee.carlrobert.codegpt.ide.toolwindow;
|
||||
|
||||
public class ChatToolWindowContent {
|
||||
}
|
||||
|
|
@ -30,14 +30,12 @@ public class ProjectToolWindowFactory implements ToolWindowFactory, DumbAware {
|
|||
}
|
||||
});
|
||||
|
||||
displayRecentConversationIfPresent(toolWindowService, contentManagerService.isChatTabSelected());
|
||||
}
|
||||
|
||||
private void displayRecentConversationIfPresent(ToolWindowService toolWindowService, boolean isChatTabSelected) {
|
||||
var conversation = ConversationsState.getCurrentConversation();
|
||||
if (conversation != null) {
|
||||
if (isChatTabSelected) {
|
||||
toolWindowService.getChatToolWindow().displayConversation(conversation);
|
||||
if (contentManagerService.isChatTabSelected()) {
|
||||
var conversation = ConversationsState.getCurrentConversation();
|
||||
if (conversation == null) {
|
||||
chatToolWindow.displayLandingView();
|
||||
} else {
|
||||
chatToolWindow.displayConversation(conversation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,9 @@ import com.intellij.openapi.project.Project;
|
|||
import ee.carlrobert.codegpt.client.ClientFactory;
|
||||
import ee.carlrobert.codegpt.ide.conversations.ConversationsState;
|
||||
import ee.carlrobert.codegpt.ide.conversations.message.Message;
|
||||
import ee.carlrobert.codegpt.ide.settings.SettingsState;
|
||||
import ee.carlrobert.codegpt.ide.toolwindow.components.SyntaxTextArea;
|
||||
import icons.Icons;
|
||||
import java.util.List;
|
||||
import javax.swing.SwingWorker;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ToolWindowService implements LafManagerListener {
|
||||
|
|
@ -43,7 +40,7 @@ public class ToolWindowService implements LafManagerListener {
|
|||
this::publish,
|
||||
(completedConversation) -> {
|
||||
ConversationsState.getInstance().saveConversation(completedConversation);
|
||||
stopGenerating(prompt, textArea, project);
|
||||
chatToolWindow.stopGenerating(prompt, textArea, project);
|
||||
},
|
||||
(errorMessage) -> {
|
||||
var currentConversation = ConversationsState.getCurrentConversation();
|
||||
|
|
@ -53,7 +50,7 @@ public class ToolWindowService implements LafManagerListener {
|
|||
ConversationsState.getInstance().saveConversation(currentConversation);
|
||||
}
|
||||
textArea.append(errorMessage);
|
||||
stopGenerating(prompt, textArea, project);
|
||||
chatToolWindow.stopGenerating(prompt, textArea, project);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
|
@ -72,26 +69,4 @@ public class ToolWindowService implements LafManagerListener {
|
|||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
public void sendMessage(String prompt, Project project) {
|
||||
chatToolWindow.addIconLabel(Icons.DefaultImageIcon, "ChatGPT:");
|
||||
|
||||
var settings = SettingsState.getInstance();
|
||||
if (settings.isGPTOptionSelected && settings.apiKey.isEmpty()) {
|
||||
chatToolWindow.notifyMissingCredential(project, "API key not provided.");
|
||||
} else if (settings.isChatGPTOptionSelected && settings.accessToken.isEmpty()) {
|
||||
chatToolWindow.notifyMissingCredential(project, "Access token not provided.");
|
||||
} else {
|
||||
var textArea = new SyntaxTextArea(true, true, SyntaxConstants.SYNTAX_STYLE_MARKDOWN);
|
||||
chatToolWindow.addTextArea(textArea);
|
||||
startRequest(prompt, textArea, project);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopGenerating(String prompt, SyntaxTextArea textArea, Project project) {
|
||||
chatToolWindow.stopGenerating(textArea, () -> {
|
||||
sendMessage(prompt, project);
|
||||
chatToolWindow.scrollToBottom();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package ee.carlrobert.codegpt.ide.toolwindow.conversations;
|
|||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import ee.carlrobert.codegpt.client.ClientCode;
|
||||
import ee.carlrobert.codegpt.ide.conversations.Conversation;
|
||||
import ee.carlrobert.codegpt.ide.conversations.ConversationsState;
|
||||
import ee.carlrobert.codegpt.ide.settings.SettingsState;
|
||||
import ee.carlrobert.codegpt.ide.toolwindow.ContentManagerService;
|
||||
import ee.carlrobert.codegpt.ide.toolwindow.ToolWindowService;
|
||||
import java.util.Comparator;
|
||||
|
|
@ -43,6 +45,7 @@ public class ConversationsToolWindow {
|
|||
private void addContent(Conversation conversation) {
|
||||
var mainPanel = new RootConversationPanel(() -> {
|
||||
ConversationsState.getInstance().setCurrentConversation(conversation);
|
||||
changeSettings(conversation);
|
||||
ContentManagerService.getInstance(project).displayChatTab();
|
||||
project.getService(ToolWindowService.class)
|
||||
.getChatToolWindow()
|
||||
|
|
@ -56,6 +59,24 @@ public class ConversationsToolWindow {
|
|||
scrollablePanel.add(mainPanel);
|
||||
}
|
||||
|
||||
private void changeSettings(Conversation conversation) {
|
||||
var settings = SettingsState.getInstance();
|
||||
var isUnofficialClient = ClientCode.UNOFFICIAL_CHATGPT.equals(conversation.getClientCode());
|
||||
settings.isChatGPTOptionSelected = isUnofficialClient;
|
||||
settings.isGPTOptionSelected = !isUnofficialClient;
|
||||
|
||||
if (!isUnofficialClient) {
|
||||
var isChatCompletions = ClientCode.CHAT_COMPLETIONS.equals(conversation.getClientCode());
|
||||
if (isChatCompletions) {
|
||||
settings.chatCompletionBaseModel = conversation.getModel();
|
||||
} else {
|
||||
settings.textCompletionBaseModel = conversation.getModel();
|
||||
}
|
||||
settings.isChatCompletionOptionSelected = isChatCompletions;
|
||||
settings.isTextCompletionOptionSelected = !isChatCompletions;
|
||||
}
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
scrollablePanel = new ScrollablePanel();
|
||||
scrollablePanel.setLayout(new BoxLayout(scrollablePanel, BoxLayout.Y_AXIS));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue