Skip to content

Commit

Permalink
Update toolwindow UI (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh authored Nov 26, 2023
1 parent 3797126 commit 1df20cc
Show file tree
Hide file tree
Showing 38 changed files with 538 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ checkstyle {
}

dependencies {
implementation("ee.carlrobert:llm-client:0.0.11")
implementation("ee.carlrobert:llm-client:0.0.12")
}

tasks {
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/ee/carlrobert/codegpt/Icons.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

public final class Icons {

public static final Icon DefaultIcon = IconLoader.getIcon("/icons/codegpt.svg", Icons.class);
public static final Icon DefaultSmallIcon =
public static final Icon Default = IconLoader.getIcon("/icons/codegpt.svg", Icons.class);
public static final Icon DefaultSmall =
IconLoader.getIcon("/icons/codegpt-small.svg", Icons.class);
public static final Icon AzureIcon = IconLoader.getIcon("/icons/azure.svg", Icons.class);
public static final Icon LlamaIcon = IconLoader.getIcon("/icons/llama.svg", Icons.class);
public static final Icon OpenAIIcon = IconLoader.getIcon("/icons/openai.svg", Icons.class);
public static final Icon SendIcon = IconLoader.getIcon("/icons/send.svg", Icons.class);
public static final Icon SparkleIcon = IconLoader.getIcon("/icons/sparkle.svg", Icons.class);
public static final Icon YouIcon = IconLoader.getIcon("/icons/you.svg", Icons.class);
public static final Icon Azure = IconLoader.getIcon("/icons/azure.svg", Icons.class);
public static final Icon Llama = IconLoader.getIcon("/icons/llama.svg", Icons.class);
public static final Icon OpenAI = IconLoader.getIcon("/icons/openai.svg", Icons.class);
public static final Icon Send = IconLoader.getIcon("/icons/send.svg", Icons.class);
public static final Icon Sparkle = IconLoader.getIcon("/icons/sparkle.svg", Icons.class);
public static final Icon You = IconLoader.getIcon("/icons/you.svg", Icons.class);
public static final Icon YouSmall = IconLoader.getIcon("/icons/you_small.png", Icons.class);
public static final Icon User = IconLoader.getIcon("/icons/user.svg", Icons.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public GenerateGitCommitMessageAction() {
super(
CodeGPTBundle.get("action.generateCommitMessage.title"),
CodeGPTBundle.get("action.generateCommitMessage.description"),
Icons.SparkleIcon);
Icons.Sparkle);
encodingManager = EncodingManager.getInstance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class AskAction extends AnAction {

public AskAction() {
super("New Chat", "Chat with CodeGPT", Icons.SparkleIcon);
super("New Chat", "Chat with CodeGPT", Icons.Sparkle);
EditorActionsUtil.registerOrReplaceAction(this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ee.carlrobert.codegpt.actions.toolwindow;

import static ee.carlrobert.codegpt.Icons.DefaultIcon;
import static ee.carlrobert.codegpt.Icons.Default;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
Expand Down Expand Up @@ -37,7 +37,7 @@ public void actionPerformed(@NotNull AnActionEvent event) {
int answer = Messages.showYesNoDialog(
"Are you sure you want to delete all conversations?",
"Clear History",
DefaultIcon);
Default);
if (answer == Messages.YES) {
var project = event.getProject();
if (project != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ public LlamaCompletionRequest buildLlamaCompletionRequest(Message message) {
COMPLETION_SYSTEM_PROMPT,
message.getPrompt(),
conversation.getMessages());
var configuration = ConfigurationState.getInstance();
return new LlamaCompletionRequest.Builder(prompt)
.setN_predict(512)
.setN_predict(configuration.getMaxTokens())
.setTemperature(configuration.getTemperature())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void addCompletionLookupValues(
for (var value : response.split(",")) {
application.runReadAction(() -> {
lookup.addItem(
LookupElementBuilder.create(value.trim()).withIcon(Icons.SparkleIcon),
LookupElementBuilder.create(value.trim()).withIcon(Icons.Sparkle),
PrefixMatcher.ALWAYS_TRUE);
});
application.invokeLater(() -> lookup.refreshUi(true, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ConfigurationState implements PersistentStateComponent<Configuratio

private String systemPrompt = COMPLETION_SYSTEM_PROMPT;
private int maxTokens = 1000;
private double temperature = 0.2;
private double temperature = 0.1;
private boolean createNewChatOnEachAction;
private boolean ignoreGitCommitTokenLimit;
private boolean methodNameGenerationEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ public class ModelIconLabel extends JBLabel {

public ModelIconLabel(String clientCode, String modelCode) {
if ("you.chat.completion".equals(clientCode)) {
setIcon(Icons.YouIcon);
setIcon(Icons.You);
return;
}

if ("chat.completion".equals(clientCode)) {
setIcon(Icons.OpenAIIcon);
setIcon(Icons.OpenAI);
}
if ("azure.chat.completion".equals(clientCode)) {
setIcon(Icons.AzureIcon);
setIcon(Icons.Azure);
}
if ("llama.chat.completion".equals(clientCode)) {
setIcon(Icons.LlamaIcon);
setIcon(Icons.Llama);
}
setText(formatModelName(modelCode));
setFont(JBFont.small().asBold());
setFont(JBFont.small());
setHorizontalAlignment(SwingConstants.LEADING);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ee.carlrobert.codegpt.toolwindow.chat;

import static ee.carlrobert.codegpt.util.UIUtil.createScrollPaneWithSmartScroller;
import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;
import static java.lang.String.format;

import com.intellij.openapi.diagnostic.Logger;
Expand All @@ -16,6 +15,7 @@
import ee.carlrobert.codegpt.conversations.Conversation;
import ee.carlrobert.codegpt.conversations.ConversationService;
import ee.carlrobert.codegpt.conversations.message.Message;
import ee.carlrobert.codegpt.settings.service.ServiceType;
import ee.carlrobert.codegpt.settings.state.SettingsState;
import ee.carlrobert.codegpt.telemetry.TelemetryAction;
import ee.carlrobert.codegpt.toolwindow.chat.components.ChatMessageResponseBody;
Expand All @@ -24,6 +24,7 @@
import ee.carlrobert.codegpt.toolwindow.chat.components.UserMessagePanel;
import ee.carlrobert.codegpt.toolwindow.chat.components.UserPromptTextArea;
import ee.carlrobert.codegpt.toolwindow.chat.components.UserPromptTextAreaHeader;
import ee.carlrobert.codegpt.toolwindow.chat.standard.StandardChatToolWindowContentManager;
import ee.carlrobert.codegpt.util.EditorUtil;
import ee.carlrobert.codegpt.util.file.FileUtil;
import java.awt.BorderLayout;
Expand Down Expand Up @@ -65,7 +66,7 @@ public BaseChatToolWindowTabPanel(
EditorUtil.getSelectedEditorSelectedText(project),
this);
userPromptTextArea = new UserPromptTextArea(this::handleSubmit, totalTokensPanel);
rootPanel = createRootPanel(settings);
rootPanel = createRootPanel(settings.getSelectedService());
userPromptTextArea.requestFocusInWindow();
userPromptTextArea.requestFocus();
}
Expand Down Expand Up @@ -201,18 +202,21 @@ private void handleSubmit(String text) {
sendMessage(message);
}

private JPanel createUserPromptPanel(SettingsState settings) {
private JPanel createUserPromptPanel(ServiceType selectedService) {
var panel = new JPanel(new BorderLayout());
panel.setBorder(JBUI.Borders.compound(
JBUI.Borders.customLine(JBColor.border(), 1, 0, 0, 0),
JBUI.Borders.empty(8)));
panel.setBackground(getPanelBackgroundColor());
panel.add(new UserPromptTextAreaHeader(settings, totalTokensPanel), BorderLayout.NORTH);
panel.add(userPromptTextArea, BorderLayout.SOUTH);
var contentManager = project.getService(StandardChatToolWindowContentManager.class);
panel.add(JBUI.Panels.simplePanel(new UserPromptTextAreaHeader(
selectedService,
totalTokensPanel,
contentManager::createNewTabPanel)), BorderLayout.NORTH);
panel.add(JBUI.Panels.simplePanel(userPromptTextArea), BorderLayout.CENTER);
return panel;
}

private JPanel createRootPanel(SettingsState settings) {
private JPanel createRootPanel(ServiceType selectedService) {
var gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 1;
Expand All @@ -226,7 +230,7 @@ private JPanel createRootPanel(SettingsState settings) {
gbc.weighty = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridy = 1;
rootPanel.add(createUserPromptPanel(settings), gbc);
rootPanel.add(createUserPromptPanel(selectedService), gbc);
return rootPanel;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ee.carlrobert.codegpt.toolwindow.chat;

import static ee.carlrobert.codegpt.util.UIUtil.getPanelBackgroundColor;

import com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel;
import com.intellij.openapi.roots.ui.componentsList.layout.VerticalStackLayout;
import ee.carlrobert.codegpt.completions.you.YouUserManager;
Expand Down Expand Up @@ -73,18 +71,15 @@ public void update() {

// TODO: Move
private JTextPane createYouCouponTextPane() {
var textPane = UIUtil.createTextPane(
return UIUtil.createTextPane(
"<html>\n"
+ "<body>\n"
+ " <p style=\"margin: 4px 0;\">Use CodeGPT coupon for free month of GPT-4.</p>\n"
+ " <p style=\"margin: 4px 0;\">\n"
+ " <a href=\"https://you.com/plans\">Sign up here</a>\n"
+ " </p>\n"
+ "</body>\n"
+ "</html>"
);
textPane.setBackground(getPanelBackgroundColor());
textPane.setFocusable(false);
return textPane;
+ "</html>",
false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.intellij.ui.JBColor;
import com.vladsch.flexmark.ast.BulletListItem;
import com.vladsch.flexmark.ast.Code;
import com.vladsch.flexmark.ast.CodeBlock;
import com.vladsch.flexmark.ast.Heading;
import com.vladsch.flexmark.ast.OrderedListItem;
import com.vladsch.flexmark.ast.Paragraph;
import com.vladsch.flexmark.html.HtmlWriter;
Expand All @@ -21,12 +23,23 @@ public class ResponseNodeRenderer implements NodeRenderer {
public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() {
return Set.of(
new NodeRenderingHandler<>(Paragraph.class, this::renderParagraph),
new NodeRenderingHandler<>(Code.class, this::renderCode)
new NodeRenderingHandler<>(Code.class, this::renderCode),
new NodeRenderingHandler<>(CodeBlock.class, this::renderCodeBlock),
new NodeRenderingHandler<>(BulletListItem.class, this::renderBulletListItem),
new NodeRenderingHandler<>(Heading.class, this::renderHeading),
new NodeRenderingHandler<>(OrderedListItem.class, this::renderOrderedListItem)
);
}

private void renderCode(Code node, NodeRendererContext context, HtmlWriter html) {
html.attr("style", "color: " + ColorUtil.toHex(new JBColor(0x00627A, 0xCC7832)));
private void renderCodeBlock(CodeBlock node, NodeRendererContext context, HtmlWriter html) {
html.attr("style", "white-space: pre-wrap;");
context.delegateRender();
}

private void renderHeading(Heading node, NodeRendererContext context, HtmlWriter html) {
if (node.getLevel() == 3) {
html.attr("style", "margin-top: 4px; margin-bottom: 4px;");
}
context.delegateRender();
}

Expand All @@ -39,6 +52,27 @@ private void renderParagraph(Paragraph node, NodeRendererContext context, HtmlWr
context.delegateRender();
}

private void renderCode(Code node, NodeRendererContext context, HtmlWriter html) {
html.attr("style", "color: " + ColorUtil.toHex(new JBColor(0x00627A, 0xCC7832)));
context.delegateRender();
}

private void renderBulletListItem(
BulletListItem node,
NodeRendererContext context,
HtmlWriter html) {
html.attr("style", "margin-bottom: 4px;");
context.delegateRender();
}

private void renderOrderedListItem(
OrderedListItem node,
NodeRendererContext context,
HtmlWriter html) {
html.attr("style", "margin-bottom: 4px;");
context.delegateRender();
}

public static class Factory implements NodeRendererFactory {

@NotNull
Expand Down
Loading

0 comments on commit 1df20cc

Please sign in to comment.