fix(hermes): save intro message to history and prevent regeneration
- Only generate intro message when no conversation history exists - Save generated intro to chatHistory so it persists across modal opens - Set up page context when loading existing conversation history - Prevent intro from being regenerated every time modal opens - Intro message now properly saved and reused like other messages
This commit is contained in:
parent
4486cec23b
commit
ecae7e9b4c
1 changed files with 24 additions and 1 deletions
25
src/ui.js
25
src/ui.js
|
|
@ -1242,11 +1242,30 @@ async function openHermesModalNew() {
|
|||
try {
|
||||
const history = loadConversationHistory();
|
||||
if (history && history.length > 0) {
|
||||
// Set up page context for existing conversation
|
||||
const pageContent = extractWebpageContent();
|
||||
const pageTitle = document.title || window.location.hostname;
|
||||
const conversationContextAppend = `
|
||||
|
||||
PAGE CONTEXT FOR THIS CONVERSATION:
|
||||
You are embedded on the webpage: "${pageTitle}"
|
||||
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. Answer questions about the page content accurately and helpfully.`;
|
||||
|
||||
setSystemMessageAppend(conversationContextAppend);
|
||||
|
||||
// Sync the loaded history with the chat.js module
|
||||
// Clear existing non-system messages and add loaded history
|
||||
const systemMsg = chatHistory.find(msg => msg.role === 'system');
|
||||
chatHistory.length = 0; // Clear array
|
||||
if (systemMsg) chatHistory.push(systemMsg);
|
||||
if (systemMsg) {
|
||||
const { getSystemMessage } = await import('./config.js');
|
||||
chatHistory.push({ role: 'system', content: getSystemMessage() });
|
||||
}
|
||||
chatHistory.push(...history);
|
||||
console.log("Chat history synced with loaded data:", chatHistory.length, "messages");
|
||||
console.log("Current chatHistory contents:", chatHistory);
|
||||
|
|
@ -1471,6 +1490,10 @@ You have complete knowledge of this page content and can reference any details,
|
|||
systemMsg.content = getSystemMessage();
|
||||
}
|
||||
|
||||
// Add the intro message to chat history so it's not regenerated
|
||||
chatHistory.push({ role: 'assistant', content: response });
|
||||
console.log("Added intro message to chat history");
|
||||
|
||||
// Add TTS and delete buttons to intro message
|
||||
const messageActions = document.createElement("div");
|
||||
messageActions.style.cssText = `
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue