diff --git a/src/ui.js b/src/ui.js index 28fb386..33b1ce3 100644 --- a/src/ui.js +++ b/src/ui.js @@ -3,7 +3,7 @@ import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js"; import hljs from "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/es/highlight.min.js"; import { extractWebpageContent } from "./content.js"; import { speakText } from "./tts.js"; -import { TTS_API_URL, API_KEY } from "./config.js"; +import { TTS_API_URL, API_KEY, setSystemMessageAppend } from "./config.js"; // Simple TTS function for chat messages (no preprocessing needed) async function speakChatText(text, voice = "alloy", rate = 1.0) { @@ -1361,23 +1361,30 @@ async function openHermesModalNew() { const pageContent = extractWebpageContent(); const pageTitle = document.title || window.location.hostname; - // Generate contextual intro message using Hermes with full page context - const contextPrompt = `You are Hermes AI, powered by Nous Research, embedded on this specific webpage. You have full access to analyze and discuss the page content. + // Set the page context in the system message for ALL conversations + const pageContextAppend = ` -PAGE INFORMATION: -Title: "${pageTitle}" +PAGE CONTEXT FOR THIS CONVERSATION: +You are embedded on the webpage: "${pageTitle}" URL: ${window.location.href} FULL PAGE CONTENT: ${pageContent} -INSTRUCTIONS: -1. Generate a warm, welcoming 3-paragraph introduction that shows you understand this specific page -2. Reference specific details from the content (names, topics, projects mentioned) -3. Explain how you can help with this page's content and related topics -4. Keep this context in mind for all future questions in this conversation +You have complete knowledge of this page content and can reference any details, names, topics, or information mentioned on this page. All questions in this conversation may relate to this page content.`; -Remember: You have access to the full page content above, so you can answer detailed questions about anything mentioned on this page, including specific people, projects, or concepts discussed.`; + setSystemMessageAppend(pageContextAppend); + + // Clear and reinitialize chat history with new system message + const systemMsg = chatHistory.find(msg => msg.role === 'system'); + if (systemMsg) { + // Update existing system message with page context + const { getSystemMessage } = await import('./config.js'); + systemMsg.content = getSystemMessage(); + } + + // Generate simple intro message + const contextPrompt = `Generate a warm, welcoming 3-paragraph introduction message. Reference specific details from the page content to show you understand what the user is viewing. Explain how you can help with this page and related topics.`; let response = ''; for await (const chunk of sendMessage(contextPrompt)) {