Ai improvements 1 (#914)

* improve netlist

* structure improvement

* chatbot enhancements

* chatbot improvements

* charbot enhancements

* Update user_manual.sql

* chatbot enhancements

* release
This commit is contained in:
Bane Stojkovic
2025-04-21 20:46:41 +02:00
committed by GitHub
parent b42fe2c34f
commit c914749413
24 changed files with 623 additions and 191 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>org.diylc</groupId>
<artifactId>diylc-parent</artifactId>
<version>5.2.0</version>
<version>5.3.0</version>
</parent>
<artifactId>diylc-swing</artifactId>
@@ -16,6 +16,8 @@ import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Objects;
import java.util.Random;
@@ -34,6 +36,10 @@ public class ChatbotPane extends JPanel {
private static final Font MONOSPACED_FONT = new Font("Monospaced", Font.PLAIN, 12);
private static final Color TERMINAL_BG = new Color(40, 40, 40);
private static final Color TERMINAL_FG = new Color(200, 200, 200);
private static final Color BUTTON_BG = new Color(70, 70, 70); // Brighter background for buttons
private static final Color BUTTON_FG = new Color(240, 240, 240); // Bright text for contrast
private static final Color BUTTON_BORDER = new Color(100, 100, 100); // Subtle border
private static final Color BUTTON_HOVER = new Color(90, 90, 90); // Hover state color
public static final String HTML_STYLE = String.format(
"<style>" + "body { font-family: %s; font-size: %dpt; color: rgb(%d,%d,%d); background-color: rgb(%d,%d,%d); padding: 0px; margin: 0; }" + "pre { white-space: pre-wrap; margin: 0; }" + ".user { color: #98C379; }" + // Softer green that's easier on the eyes
".assistant { color: #61AFEF; }" + // Lighter, more vibrant blue
@@ -64,9 +70,21 @@ public class ChatbotPane extends JPanel {
super();
this.swingUI = swingUI;
this.plugInPort = plugInPort;
this.chatbotService = plugInPort.getChatbotService();
this.chatbotService = new ChatbotService(plugInPort);
setName("AI Assistant");
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
e.consume();
}
@Override
public void mousePressed(MouseEvent e) {
e.consume();
}
});
// Set panel background color
setBackground(TERMINAL_BG);
@@ -99,12 +117,15 @@ public class ChatbotPane extends JPanel {
int lineHeight = getPromptArea().getFontMetrics(getPromptArea().getFont()).getHeight();
int desiredHeight = lineHeight * 3 + 10; // 3 lines + padding
// Set minimum and preferred size for both text area and scroll pane
Dimension promptSize = new Dimension(200, desiredHeight);
getPromptArea().setMinimumSize(promptSize);
getPromptArea().setPreferredSize(promptSize);
promptScrollPane.setMinimumSize(new Dimension(200, desiredHeight + 10));
promptScrollPane.setPreferredSize(new Dimension(200, desiredHeight + 10));
// Set minimum and preferred size for scroll pane
promptScrollPane.setMinimumSize(new Dimension(200, desiredHeight));
promptScrollPane.setPreferredSize(new Dimension(200, desiredHeight));
// Enable vertical scrolling
getPromptArea().setLineWrap(true);
getPromptArea().setWrapStyleWord(true);
getPromptArea().setRows(3); // Set initial rows
promptScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
gbc.gridx = 0;
gbc.gridy = 3;
@@ -163,20 +184,19 @@ public class ChatbotPane extends JPanel {
promptArea.addKeyListener(new java.awt.event.KeyAdapter() {
@Override
public void keyPressed(java.awt.event.KeyEvent e) {
if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER && !e.isShiftDown()) {
e.consume(); // Prevent the newline from being added
if (getAskButton().isEnabled()) {
getAskButton().doClick();
if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
if (e.isShiftDown()) {
// Insert newline for Shift+Enter
promptArea.insert("\n", promptArea.getCaretPosition());
} else {
e.consume(); // Always consume Enter to prevent multiple newlines
if (getAskButton().isEnabled()) {
getAskButton().doClick();
}
}
}
}
});
// Calculate height based on font metrics
int lineHeight = promptArea.getFontMetrics(promptArea.getFont()).getHeight();
int desiredHeight = lineHeight * 3 + 10; // 3 lines + padding
promptArea.setMinimumSize(new Dimension(200, desiredHeight));
promptArea.setPreferredSize(new Dimension(200, desiredHeight));
// Add placeholder text behavior
final String placeholder = "Ask me anything";
@@ -256,7 +276,16 @@ public class ChatbotPane extends JPanel {
fetchChatHistory();
if (this.subscriptionInfo != null) {
getPremiumButton().setVisible(FREE_TIER.equals(this.subscriptionInfo.getTier()));
String subscriptionInfoText = getSubscriptionInfoText();
String subscriptionInfoText = "Your are currently subscribed to the '" + this.subscriptionInfo.getTier() + "' tier, expiring on " + this.subscriptionInfo.getEndDate() + ", with " + this.subscriptionInfo.getRemainingCredits() + " credits remaining.";
if (FREE_TIER.equals(this.subscriptionInfo.getTier())) {
subscriptionInfoText +=
" To subscribe to one of the premium tiers, unlock advanced AI models and get more credits, visit <a href='http://" + GET_PREMIUM_URL + "'>" + GET_PREMIUM_URL + "</a> and become a Patreon supporter. " +
"All the details about the AI Assistant limits and other benefits will be specified there. " +
"If you are already a Patreon supporter, make sure to link your account with the DIYLC Cloud account from the 'Cloud' menu.";
} else {
subscriptionInfoText += " Thank you for supporting further development of DIYLC!";
}
appendSection(ChatbotService.SYSTEM, subscriptionInfoText);
}
getAskButton().setEnabled(true);
@@ -265,31 +294,15 @@ public class ChatbotPane extends JPanel {
// Scroll to the end of the chat pane
SwingUtilities.invokeLater(() -> {
if (getChatEditorPane().getParent() == null) {
return;
}
JScrollPane scrollPane = (JScrollPane) getChatEditorPane().getParent().getParent();
JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
verticalScrollBar.setValue(verticalScrollBar.getMaximum());
});
}
private String getSubscriptionInfoText() {
String subscriptionInfoText = String.format(
"Your are currently subscribed to the '%s' tier, expiring on %s, with %d credits remaining.",
this.subscriptionInfo.getTier(),
this.subscriptionInfo.getEndDate(),
this.subscriptionInfo.getRemainingCredits());
if (FREE_TIER.equals(this.subscriptionInfo.getTier())) {
subscriptionInfoText += String.format(
" To subscribe to one of the premium tiers, unlock advanced AI models and get more credits, visit <a href='http://%s'>%s</a> and become a Patreon supporter. " +
"All the details about the AI Assistant limits and other benefits will be specified there. " +
"If you are already a Patreon supporter, make sure to link your account with the DIYLC Cloud account from the 'Cloud' menu.",
GET_PREMIUM_URL, GET_PREMIUM_URL);
} else {
subscriptionInfoText += " Thank you for supporting further development of DIYLC!";
}
return subscriptionInfoText;
}
private void fetchChatHistory() {
try {
List<ChatMessageEntity> chatHistory = plugInPort.getChatbotService().getChatHistory();
@@ -364,11 +377,7 @@ public class ChatbotPane extends JPanel {
public JButton getAskButton() {
if (askButton == null) {
askButton = new JButton(LangUtil.translate("Send"));
askButton.setBackground(TERMINAL_BG);
askButton.setForeground(TERMINAL_FG);
askButton.setFocusPainted(false);
askButton.setBorderPainted(true);
askButton.setEnabled(false);
styleButton(askButton);
askButton.addActionListener(e -> {
String prompt = getPromptArea().getText();
appendSection(ChatbotService.USER, ME + prompt);
@@ -426,11 +435,7 @@ public class ChatbotPane extends JPanel {
public JButton getClearButton() {
if (clearButton == null) {
clearButton = new JButton(LangUtil.translate("Clear"));
clearButton.setBackground(TERMINAL_BG);
clearButton.setForeground(TERMINAL_FG);
clearButton.setFocusPainted(false);
clearButton.setBorderPainted(true);
clearButton.setEnabled(false);
styleButton(clearButton);
clearButton.addActionListener(e -> {
// Show confirmation dialog
int result = swingUI.showConfirmDialog(
@@ -469,13 +474,9 @@ public class ChatbotPane extends JPanel {
public JButton getPremiumButton() {
if (premiumButton == null) {
premiumButton = new JButton(LangUtil.translate("Get Premium"));
premiumButton.setBackground(TERMINAL_BG);
premiumButton.setForeground(TERMINAL_FG);
premiumButton.setFocusPainted(false);
premiumButton.setBorderPainted(true);
styleButton(premiumButton);
premiumButton.setVisible(false);
premiumButton.addActionListener(e -> {
try {
java.awt.Desktop.getDesktop().browse(new java.net.URI("http://diy-fever.com/get-premium"));
} catch (Exception ex) {
@@ -487,4 +488,45 @@ public class ChatbotPane extends JPanel {
}
return premiumButton;
}
private void styleButton(JButton button) {
button.setBackground(BUTTON_BG);
button.setForeground(BUTTON_FG);
button.setEnabled(true); // Reset enabled state to ensure proper color
button.setFocusPainted(false);
button.setBorderPainted(true);
button.setContentAreaFilled(false);
button.setOpaque(true);
// Create a simple rounded border with padding
button.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(BUTTON_BORDER, 1),
BorderFactory.createEmptyBorder(4, 8, 4, 8)
));
// Add hover effect
button.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
if (button.isEnabled()) {
button.setBackground(BUTTON_HOVER);
}
}
public void mouseExited(java.awt.event.MouseEvent evt) {
if (button.isEnabled()) {
button.setBackground(BUTTON_BG);
}
}
});
// Set minimum and preferred size based on button type
if (button == premiumButton) {
// Wider size for Premium button
button.setMinimumSize(new Dimension(120, 25));
button.setPreferredSize(new Dimension(120, 25));
} else {
// Standard size for other buttons
button.setMinimumSize(new Dimension(80, 25));
button.setPreferredSize(new Dimension(80, 25));
}
}
}
@@ -48,7 +48,7 @@ public class ChatbotPlugin implements IPlugIn {
@Override
public EnumSet<EventType> getSubscribedEventTypes() {
return EnumSet.of(EventType.FILE_STATUS_CHANGED, EventType.PROJECT_LOADED,
return EnumSet.of(EventType.PROJECT_SAVED, EventType.PROJECT_LOADED,
EventType.CLOUD_LOGGED_IN, EventType.CLOUD_LOGGED_OUT);
}
@@ -56,7 +56,7 @@ public class ChatbotPlugin implements IPlugIn {
@Override
public void processMessage(EventType eventType, Object... params) {
switch (eventType) {
case FILE_STATUS_CHANGED:
case PROJECT_SAVED:
case PROJECT_LOADED:
case CLOUD_LOGGED_IN:
case CLOUD_LOGGED_OUT: