fix(hermes): set page context in system message for entire conversation
- Use setSystemMessageAppend to add page context to system message - All follow-up questions now have full page context available - Update existing system message in chatHistory with page content - Hermes can now reference specific details (like Nathan) in follow-up questions - Maintains coherent conversation with proper page context throughout
This commit is contained in:
parent
71a2c3d00d
commit
712473f516
1 changed files with 18 additions and 11 deletions
29
src/ui.js
29
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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue