feat(hermes): implement dual system prompts for intro vs conversation

- Create specialized intro system prompt for 3-paragraph welcome generation
- Use separate conversation system prompt for follow-up questions
- Intro prompt: focused on generating structured welcome message
- Conversation prompt: optimized for answering questions about page content
- Use translation sendMessage for custom history in intro generation
- Maintain page context throughout conversation while separating concerns
This commit is contained in:
Russell Ballestrini 2025-07-02 08:36:43 -04:00
parent 712473f516
commit 4110a8130b

View file

@ -1361,8 +1361,43 @@ async function openHermesModalNew() {
const pageContent = extractWebpageContent();
const pageTitle = document.title || window.location.hostname;
// Set the page context in the system message for ALL conversations
const pageContextAppend = `
// FIRST: Generate intro message with specialized intro system prompt
const introSystemPrompt = `You are Hermes AI, powered by Nous Research, embedded on a webpage. Your task is to generate a warm, welcoming 3-paragraph introduction that shows you understand the specific page the user is viewing.
PAGE INFORMATION:
Title: "${pageTitle}"
URL: ${window.location.href}
FULL PAGE CONTENT:
${pageContent}
Generate a 3-paragraph introduction that:
1. Introduces yourself as Hermes AI and acknowledges the specific page/content
2. Explains how you can help with this page content and related topics
3. Invites questions and explains your capabilities
Reference specific details from the page content to show understanding.`;
const introPrompt = `Generate the welcoming introduction message now.`;
// Create temporary chat history for intro generation
const introHistory = [
{ role: "system", content: introSystemPrompt },
{ role: "user", content: introPrompt }
];
// Generate intro with specialized system prompt
let response = '';
const { sendMessage: sendMessageWithHistory } = await import('./translation.js');
// Use the translation sendMessage which accepts custom history
for await (const chunk of sendMessageWithHistory(introHistory)) {
response += chunk;
introMsg.innerHTML = marked.parse(response);
}
// SECOND: Set up conversation system prompt for follow-up messages
const conversationContextAppend = `
PAGE CONTEXT FOR THIS CONVERSATION:
You are embedded on the webpage: "${pageTitle}"
@ -1371,27 +1406,17 @@ URL: ${window.location.href}
FULL PAGE CONTENT:
${pageContent}
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.`;
You have complete knowledge of this page content and can reference any details, names, topics, or information mentioned on this page. Answer questions about the page content accurately and helpfully.`;
setSystemMessageAppend(pageContextAppend);
setSystemMessageAppend(conversationContextAppend);
// Clear and reinitialize chat history with new system message
// Update the chat history system message for follow-up conversations
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)) {
response += chunk;
introMsg.innerHTML = marked.parse(response);
}
// Add TTS and delete buttons to intro message
const messageActions = document.createElement("div");
messageActions.style.cssText = `