Switch to openai-client, add conversation history empty label, remove unofficial reverse proxy (closes #43)

This commit is contained in:
Carl-Robert Linnupuu 2023-03-21 00:21:07 +00:00
parent 33a5e520f2
commit 57e1095dd1
85 changed files with 619 additions and 1828 deletions

View file

@ -0,0 +1,61 @@
package ee.carlrobert.codegpt.toolwindow;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.ContentManagerEvent;
import com.intellij.ui.content.ContentManagerListener;
import com.intellij.ui.jcef.JBCefBrowser;
import ee.carlrobert.codegpt.client.ClientFactory;
import ee.carlrobert.codegpt.account.AccountDetailsState;
import ee.carlrobert.codegpt.conversations.ConversationsState;
import ee.carlrobert.codegpt.toolwindow.chat.ChatGptToolWindow;
import ee.carlrobert.codegpt.toolwindow.conversations.ConversationsToolWindow;
import javax.swing.JComponent;
import org.jetbrains.annotations.NotNull;
public class ProjectToolWindowFactory implements ToolWindowFactory, DumbAware {
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
var chatToolWindow = new ChatGptToolWindow(project);
var conversationsToolWindow = new ConversationsToolWindow(project);
var toolWindowService = project.getService(ToolWindowService.class);
toolWindowService.setChatToolWindow(chatToolWindow);
var contentManagerService = project.getService(ContentManagerService.class);
addContent(toolWindow, chatToolWindow.getContent(), "Chat");
addContent(toolWindow, conversationsToolWindow.getContent(), "Conversation History");
addContent(toolWindow, new JBCefBrowser("https://chat.openai.com/chat").getComponent(), "Browser");
toolWindow.addContentManagerListener(new ContentManagerListener() {
public void selectionChanged(@NotNull ContentManagerEvent event) {
var content = event.getContent();
if ("Conversation History".equals(content.getTabName()) && content.isSelected()) {
conversationsToolWindow.refresh();
} else if ("Chat".equals(content.getTabName()) && content.isSelected()) {
ClientFactory.getBillingClient()
.getCreditUsageAsync(creditUsage -> {
var accountDetails = AccountDetailsState.getInstance();
accountDetails.totalAmountGranted = creditUsage.getTotalGranted();
accountDetails.totalAmountUsed = creditUsage.getTotalUsed();
});
}
}
});
if (contentManagerService.isChatTabSelected(toolWindow.getContentManager())) {
var conversation = ConversationsState.getCurrentConversation();
if (conversation == null) {
chatToolWindow.displayLandingView();
} else {
chatToolWindow.displayConversation(conversation);
}
}
}
public void addContent(ToolWindow toolWindow, JComponent panel, String displayName) {
var contentManager = toolWindow.getContentManager();
var content = contentManager.getFactory().createContent(panel, displayName, false);
contentManager.addContent(content);
}
}