mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-16 19:44:36 +00:00
Switch to openai-client, add conversation history empty label, remove unofficial reverse proxy (closes #43)
This commit is contained in:
parent
33a5e520f2
commit
57e1095dd1
85 changed files with 619 additions and 1828 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue