From e8bef319dabaf2ac841e55d4d8a458ed274a5b9d Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 2 Jul 2025 08:08:46 -0400 Subject: [PATCH] feat(hermes): generate contextual intro message using LLM - Use Hermes AI to generate page-specific welcome message - Extract current page content and title for context - Create 3-paragraph intro that acknowledges specific page content - Show loading message while generating contextual intro - Fallback to basic intro if generation fails - Make intro relevant to what user is actually viewing --- src/ui.js | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/ui.js b/src/ui.js index b106a5e..8a6d79f 100644 --- a/src/ui.js +++ b/src/ui.js @@ -805,7 +805,7 @@ async function openHermesModalNew() { const actions = [ { text: "📁 Upload File", action: () => document.querySelector('[data-uncloseai-file-input]')?.click() }, { text: "🔄 Refresh Models", action: loadModels }, - { text: "🗑️ Clear Chat", action: () => { + { text: "🗑️ Clear Chat", action: async () => { if (confirm("Clear all conversation history?")) { chatBox.innerHTML = ''; clearConversationHistory(); @@ -817,7 +817,7 @@ async function openHermesModalNew() { console.log("Chat history cleared, reset to system message only"); // Re-add intro message - addIntroMessage(); + await addIntroMessage(); } }} ]; @@ -1332,15 +1332,15 @@ async function openHermesModalNew() { chatArea.scrollTop = chatArea.scrollHeight; } else { // Add intro message if no history - addIntroMessage(); + await addIntroMessage(); } } catch (error) { console.error("Failed to load conversation history:", error); - addIntroMessage(); + await addIntroMessage(); } }; - const addIntroMessage = () => { + const addIntroMessage = async () => { const introMsg = document.createElement("div"); introMsg.style.cssText = ` align-self: flex-start; @@ -1351,8 +1351,42 @@ async function openHermesModalNew() { box-shadow: 0 1px 2px rgba(0,0,0,0.1); color: #495057; `; - introMsg.innerHTML = `👋 Hi! I'm Hermes AI. I can help you understand this page, answer questions, or assist with various tasks. How can I help you today?`; + + // Show loading message first + introMsg.innerHTML = 'Analyzing page and generating welcome message...'; chatBox.appendChild(introMsg); + + try { + // Get page content for context + const pageContent = extractWebpageContent(); + const pageTitle = document.title || window.location.hostname; + + // Generate contextual intro message using Hermes + const contextPrompt = `You are Hermes AI, embedded on a webpage. Generate a warm, welcoming 3-paragraph introduction message that: + +1. First paragraph: Introduce yourself as Hermes AI (powered by Nous Research) and acknowledge the specific page/content the user is viewing +2. Second paragraph: Explain how you can help with this specific page content and related topics +3. Third paragraph: Invite questions and explain your capabilities + +Page title: "${pageTitle}" +Page content preview: "${pageContent.substring(0, 1000)}..." + +Keep it conversational, helpful, and specific to this page context. Use a friendly tone and make it clear you understand what page they're on.`; + + let response = ''; + for await (const chunk of sendMessage(contextPrompt)) { + response += chunk; + introMsg.innerHTML = marked.parse(response); + } + + // Save this intro as part of the conversation + saveConversationHistory(chatHistory); + + } catch (error) { + console.error("Failed to generate contextual intro:", error); + // Fallback to basic intro + introMsg.innerHTML = `👋 Hi! I'm Hermes AI. I can help you understand this page, answer questions, or assist with various tasks. How can I help you today?`; + } }; await loadHistory();