ProxyAI/src/main/java/ee/carlrobert/codegpt/util/OverlayUtils.java
Carl-Robert 45908e69df
#178 - Add support for running local LLMs via LLaMA C/C++ port (#249)
* Initial implementation of integrating llama.cpp to run LLaMA models locally

* Move submodule

* Copy llama submodule to bundle

* Support for downloading models from IDE

* Code cleanup

* Store port field

* Replace service selection radio group with dropdown

* Add quantization support + other fixes

* Add option to override host

* Fix override host handler

* Disable port field when override host enabled

* Design updates

* Fix llama settings configuration, design changes, clean up code

* Improve You.com coupon design

* Add new Phind model and help tooltip

* Fetch you.com subscription

* Add CodeBooga model, fix downloadable model selection

* Chat history support

* Code refactoring, minor bug fixes

* UI updates, several bug fixes, removed code llama python model

* Code cleanup, enable llama port only on macOS

* Change downloaded gguf models path

* Move some of the labels to codegpt bundle

* Minor fixes

* Remove ToRA model, add help texts

* Fix test

* Modify description
2023-11-03 12:00:24 +02:00

130 lines
5.2 KiB
Java

package ee.carlrobert.codegpt.util;
import static com.intellij.openapi.ui.Messages.CANCEL;
import static com.intellij.openapi.ui.Messages.OK;
import static ee.carlrobert.codegpt.Icons.DefaultIcon;
import static java.util.Objects.requireNonNull;
import com.intellij.execution.ExecutionBundle;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.DoNotAskOption;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.Balloon.Position;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.JBFont;
import com.intellij.util.ui.JBUI;
import ee.carlrobert.codegpt.CodeGPTBundle;
import ee.carlrobert.codegpt.conversations.ConversationsState;
import ee.carlrobert.codegpt.indexes.FolderStructureTreePanel;
import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.JComponent;
import org.jetbrains.annotations.NotNull;
public class OverlayUtils {
public static void showNotification(String content, NotificationType type) {
Notifications.Bus.notify(new Notification("CodeGPT Notification Group", "CodeGPT", content, type));
}
public static int showFileStructureDialog(Project project, FolderStructureTreePanel folderStructureTreePanel) {
var dialogBuilder = new DialogBuilder(project);
dialogBuilder.setNorthPanel(JBUI.Panels.simplePanel(new JBLabel(
"<html>" +
"<p>Indexing files enables direct queries related to your codebase.</p>" +
"<br/>" +
"<p>File indexing occurs locally on your computer; no files are sent to any 3rd party services.</p>" +
"<p>For additional information, refer to the <a href=\"https://google.com\">CodeGPT documentation</a>.</p>" +
"</html>")
.setCopyable(true)
.setAllowAutoWrapping(true)
.withFont(JBFont.medium()))
.withBorder(JBUI.Borders.emptyBottom(12)));
dialogBuilder.setCenterPanel(folderStructureTreePanel.getPanel());
dialogBuilder.addOkAction().setText("Start Indexing");
dialogBuilder.addCancelAction();
dialogBuilder.setTitle("Choose Files for Indexing");
return dialogBuilder.show();
}
public static int showDeleteConversationDialog() {
return Messages.showYesNoDialog(
CodeGPTBundle.get("dialog.deleteConversation.description"),
CodeGPTBundle.get("dialog.deleteConversation.title"),
DefaultIcon);
}
public static int showTokenLimitExceededDialog() {
return MessageDialogBuilder.okCancel(
CodeGPTBundle.get("dialog.tokenLimitExceeded.title"),
CodeGPTBundle.get("dialog.tokenLimitExceeded.description"))
.yesText(CodeGPTBundle.get("dialog.tokenLimitExceeded.continue"))
.noText(CodeGPTBundle.get("dialog.tokenLimitExceeded.cancel"))
.icon(DefaultIcon)
.doNotAsk(new DoNotAskOption.Adapter() {
@Override
public void rememberChoice(boolean isSelected, int exitCode) {
if (isSelected) {
ConversationsState.getInstance().discardAllTokenLimits();
}
}
@NotNull
@Override
public String getDoNotShowMessage() {
return ExecutionBundle.message("don.t.ask.again");
}
@Override
public boolean shouldSaveOptionsOnCancel() {
return true;
}
})
.guessWindowAndAsk() ? OK : CANCEL;
}
public static void showSelectedEditorSelectionWarning(AnActionEvent event) {
var locationOnScreen = ((MouseEvent) event.getInputEvent()).getLocationOnScreen();
locationOnScreen.y = locationOnScreen.y - 16;
showWarningBalloon(
EditorUtils.getSelectedEditor(requireNonNull(event.getProject())) == null
? "Unable to locate a selected editor"
: "Please select a target code before proceeding",
locationOnScreen);
}
public static void showWarningBalloon(String content, Point locationOnScreen) {
showBalloon(content, MessageType.WARNING, locationOnScreen);
}
public static void showInfoBalloon(String content, Point locationOnScreen) {
showBalloon(content, MessageType.INFO, locationOnScreen);
}
private static void showBalloon(String content, MessageType messageType, Point locationOnScreen) {
JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder(content, messageType, null)
.setFadeoutTime(2500)
.createBalloon()
.show(RelativePoint.fromScreen(locationOnScreen), Balloon.Position.above);
}
public static void showBalloon(String content, MessageType messageType, JComponent component) {
JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder(content, messageType, null)
.setFadeoutTime(2500)
.createBalloon()
.show(RelativePoint.getSouthOf(component), Position.below);
}
}