chatbot enhancements

This commit is contained in:
Bane Stojkovic
2025-04-07 21:29:57 +02:00
parent 0c8883529d
commit 99f8030fac
6 changed files with 620 additions and 584 deletions
@@ -13,6 +13,8 @@ import org.diylc.swing.ISwingUI;
import org.diylc.utils.FileUtils; import org.diylc.utils.FileUtils;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*; import java.awt.*;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@@ -26,6 +28,7 @@ public class ChatbotPane extends JPanel {
public static final String ME = "Me: "; public static final String ME = "Me: ";
public static final String AI_ASSISTANT = "AI Assistant: "; public static final String AI_ASSISTANT = "AI Assistant: ";
public static final String FREE_TIER = "Free"; public static final String FREE_TIER = "Free";
public static final String GET_PREMIUM_URL = "www.diy-fever.com/get-premium";
public static Font DEFAULT_FONT = new Font("Square721 BT", Font.PLAIN, 12); public static Font DEFAULT_FONT = new Font("Square721 BT", Font.PLAIN, 12);
private static final Font MONOSPACED_FONT = new Font("Monospaced", Font.PLAIN, 12); private static final Font MONOSPACED_FONT = new Font("Monospaced", Font.PLAIN, 12);
@@ -35,7 +38,10 @@ public class ChatbotPane extends JPanel {
"<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 "<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 ".assistant { color: #61AFEF; }" + // Lighter, more vibrant blue
".system { color: #E5C07B; }" + // Warmer, muted yellow ".system { color: #E5C07B; }" + // Warmer, muted yellow
".temporary { color: #555555; }" + "</style>", MONOSPACED_FONT.getFamily(), ".temporary { color: #555555; }" +
"a { color: #C678DD; text-decoration: none; }" + // Purple link color
"a:hover { color: #E06C75; text-decoration: underline; }" + // Red hover color
"</style>", MONOSPACED_FONT.getFamily(),
MONOSPACED_FONT.getSize(), TERMINAL_FG.getRed(), TERMINAL_FG.getGreen(), MONOSPACED_FONT.getSize(), TERMINAL_FG.getRed(), TERMINAL_FG.getGreen(),
TERMINAL_FG.getBlue(), TERMINAL_BG.getRed(), TERMINAL_BG.getGreen(), TERMINAL_BG.getBlue()); TERMINAL_FG.getBlue(), TERMINAL_BG.getRed(), TERMINAL_BG.getGreen(), TERMINAL_BG.getBlue());
private static final Color PROMPT_BG = new Color(60, 60, 60); // Slightly brighter than TERMINAL_BG private static final Color PROMPT_BG = new Color(60, 60, 60); // Slightly brighter than TERMINAL_BG
@@ -245,13 +251,25 @@ public class ChatbotPane extends JPanel {
} else { } else {
if (subscriptionInfo != null) { if (subscriptionInfo != null) {
getPremiumButton().setVisible(FREE_TIER.equals(subscriptionInfo.getTier())); getPremiumButton().setVisible(FREE_TIER.equals(subscriptionInfo.getTier()));
appendSection(ChatbotService.SYSTEM, String subscriptionInfoText = "Your are currently subscribed to the '" + subscriptionInfo.getTier() + "' tier, expiring on " + subscriptionInfo.getEndDate() + ", with " + subscriptionInfo.getRemainingCredits() + " credits remaining.";
"Your are currently subscribed to the '" + subscriptionInfo.getTier() + "' tier, expiring on " + subscriptionInfo.getEndDate() + ", with " + subscriptionInfo.getRemainingCredits() + " credits remaining.");
if (FREE_TIER.equals(subscriptionInfo.getTier())) {
subscriptionInfoText +=
" To subscribe to the Premium tier, unlock advanced AI models and virtually limitless usage, visit <a href='http://" + GET_PREMIUM_URL + "'>" + GET_PREMIUM_URL + "</a>.";
}
appendSection(ChatbotService.SYSTEM, subscriptionInfoText);
} }
fetchChatHistory(); fetchChatHistory();
getAskButton().setEnabled(true); getAskButton().setEnabled(true);
getClearButton().setEnabled(true); getClearButton().setEnabled(true);
} }
// Scroll to the end of the chat pane
SwingUtilities.invokeLater(() -> {
JScrollPane scrollPane = (JScrollPane) getChatEditorPane().getParent().getParent();
JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
verticalScrollBar.setValue(verticalScrollBar.getMaximum());
});
} }
private void fetchChatHistory() { private void fetchChatHistory() {
@@ -278,6 +296,22 @@ public class ChatbotPane extends JPanel {
chatEditorPane.setContentType("text/html"); chatEditorPane.setContentType("text/html");
chatEditorPane.setText(HTML_STYLE + "<body></body>"); chatEditorPane.setText(HTML_STYLE + "<body></body>");
chatEditorPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent hle) {
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
System.out.println(hle.getURL());
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(hle.getURL().toURI());
} catch (Exception ex) {
LOG.error("Could not open link: " + hle.getURL(), ex);
}
}
}
});
refreshChat(null); refreshChat(null);
} }
return chatEditorPane; return chatEditorPane;
@@ -58,10 +58,12 @@ public class ChatbotPlugin implements IPlugIn {
switch (eventType) { switch (eventType) {
case FILE_STATUS_CHANGED: case FILE_STATUS_CHANGED:
case PROJECT_LOADED: case PROJECT_LOADED:
getChatbotPane().refreshChat(null);
break;
case CLOUD_LOGGED_IN: case CLOUD_LOGGED_IN:
case CLOUD_LOGGED_OUT: case CLOUD_LOGGED_OUT:
SubscriptionEntity subscriptionInfo = null; SubscriptionEntity subscriptionInfo = null;
if (params.length > 0) { if (params.length > 0 && params[0] instanceof SubscriptionEntity) {
subscriptionInfo = (SubscriptionEntity) params[0]; subscriptionInfo = (SubscriptionEntity) params[0];
} }
getChatbotPane().refreshChat(subscriptionInfo); getChatbotPane().refreshChat(subscriptionInfo);
+1 -1
View File
@@ -235,7 +235,7 @@ INSERT INTO diylc_knowledge_base(category, section, content) VALUES ('User Manua
'DIYLC AI Assistant is an integrated feature that allows users to interact with DIY Layout Creator (DIYLC) using natural language. It functions as a chatbot powered by the OpenAI API to generate helpful responses. The AI Assistant is available only while logged into the DIYLC Cloud with an active account and requires an internet connection. 'DIYLC AI Assistant is an integrated feature that allows users to interact with DIY Layout Creator (DIYLC) using natural language. It functions as a chatbot powered by the OpenAI API to generate helpful responses. The AI Assistant is available only while logged into the DIYLC Cloud with an active account and requires an internet connection.
There are two subscription tiers for using the AI Assistant: There are two subscription tiers for using the AI Assistant:
- Free Tier: Provides limited monthly usage and access to basic AI models. This option is automatically available to all registered DIYLC Cloud users. - Free Tier: Provides limited monthly usage and access to basic AI models. This option is automatically available to all registered DIYLC Cloud users.
- Premium Tier: Offers up to 1000 requests per month using more advanced AI models. The Premium subscription is exclusively available to Patreon supporters with the "Premium AI" tier. Once you become a premium supporter, your premium status will be semi-automatically transferred to your DIYLC Cloud account. If your email used to subscribe to the premium tier is different from the email used to login to the DIYLC Cloud, please reach out to bancika@gmail.com to manually transfer your premium status. - Premium Tier: Offers up to 1000 requests per month using more advanced AI models. The Premium subscription can be purchased at http://www.diy-fever.com/get-premium. If your email used to subscribe to the premium tier is different from the email used to login to the DIYLC Cloud, please reach out to bancika@gmail.com to manually activate your premium status.
'); ');
DELETE FROM diylc_knowledge_base WHERE section = 'AI Assitant/Chatbot/ChatGPT/GPT - Using the AI Assistant'; DELETE FROM diylc_knowledge_base WHERE section = 'AI Assitant/Chatbot/ChatGPT/GPT - Using the AI Assistant';