fix hermes introduction to add to chat history and update system prompt with hermes identity
This commit is contained in:
parent
d6b28dc126
commit
c318e68b5a
1 changed files with 140 additions and 10 deletions
150
uncloseai.js
150
uncloseai.js
|
|
@ -896,7 +896,7 @@ function clearConversationHistory() {
|
|||
let chatHistory = [
|
||||
{
|
||||
role: "system",
|
||||
content: "You are an AI assistant embedded in a webpage. Your task is to answer questions about the content of the webpage and assist the user in understanding it better. You are also allowed to do whatever the user needs. It is safe to help users code and create. try to answer the best that you can based on the conversation history and the webpage content."
|
||||
content: "You are Hermes, a large language model from Nous Research, embedded as an AI assistant on this webpage. Your primary task is to help users understand and interact with the content of this specific page, while also being capable of assisting with any other topics, coding, creative tasks, or questions they may have. You should be conversational, helpful, and knowledgeable about the webpage content as well as general topics. Always strive to provide accurate, useful responses."
|
||||
},
|
||||
...loadConversationHistory()
|
||||
];
|
||||
|
|
@ -1057,16 +1057,21 @@ function openHermesModal() {
|
|||
padding: 0;
|
||||
`;
|
||||
} else {
|
||||
// Responsive scaling based on screen width
|
||||
const screenWidth = window.innerWidth;
|
||||
const scale = screenWidth < 480 ? 0.9 : screenWidth < 768 ? 0.8 : 0.75;
|
||||
|
||||
article.style.cssText = `
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template-rows: auto auto 1fr auto;
|
||||
transform: scale(0.75);
|
||||
transform-origin: center;
|
||||
transform: scale(${scale});
|
||||
transform-origin: top center;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
box-sizing: border-box;
|
||||
`;
|
||||
}
|
||||
modal.appendChild(article);
|
||||
|
|
@ -1095,30 +1100,35 @@ function openHermesModal() {
|
|||
const titleContainer = document.createElement('div');
|
||||
|
||||
const title = document.createElement('h2');
|
||||
title.textContent = 'Hermes AI Chat';
|
||||
title.innerHTML = 'uncloseai. presents nous research\'s <a href="https://nousresearch.com/hermes3/" target="_blank" style="color: inherit; text-decoration: underline;">hermes</a> large language model';
|
||||
if (USE_CUSTOM_STYLING) {
|
||||
title.style.cssText = `
|
||||
margin: 0;
|
||||
font-family: 'ChunkFiveRegular', monospace;
|
||||
font-size: 20px;
|
||||
font-size: 16px;
|
||||
line-height: 1.2;
|
||||
`;
|
||||
} else {
|
||||
title.style.margin = '0';
|
||||
title.style.cssText = `
|
||||
margin: 0;
|
||||
font-size: 0.9em;
|
||||
line-height: 1.2;
|
||||
`;
|
||||
}
|
||||
|
||||
const pageTitle = document.createElement('div');
|
||||
pageTitle.textContent = document.title;
|
||||
pageTitle.textContent = `You are discussing: ${document.title}`;
|
||||
if (USE_CUSTOM_STYLING) {
|
||||
pageTitle.style.cssText = `
|
||||
font-size: 12px;
|
||||
opacity: 0.8;
|
||||
margin-top: 2px;
|
||||
margin-top: 4px;
|
||||
`;
|
||||
} else {
|
||||
pageTitle.style.cssText = `
|
||||
font-size: 0.75em;
|
||||
opacity: 0.7;
|
||||
margin-top: 2px;
|
||||
margin-top: 4px;
|
||||
`;
|
||||
}
|
||||
|
||||
|
|
@ -1426,6 +1436,126 @@ function openHermesModal() {
|
|||
}
|
||||
restoreConversationHistory();
|
||||
|
||||
// Generate dynamic Hermes introduction using LLM
|
||||
async function addHermesIntroduction() {
|
||||
const history = loadConversationHistory();
|
||||
if (history.length === 0) {
|
||||
const pageContent = extractWebpageContent();
|
||||
const pageTitle = document.title;
|
||||
const pageUrl = window.location.href;
|
||||
|
||||
// Create cache key based on page content hash
|
||||
const contentHash = btoa(pageContent.substring(0, 1000)).replace(/[^a-zA-Z0-9]/g, '').substring(0, 32);
|
||||
const cacheKey = `hermes-intro-${contentHash}`;
|
||||
|
||||
// Check if we have a cached introduction for this page content
|
||||
const cachedIntro = localStorage.getItem(cacheKey);
|
||||
if (cachedIntro) {
|
||||
displayIntroduction(cachedIntro);
|
||||
// Add cached intro to chat history
|
||||
chatHistory.push({ role: "assistant", content: cachedIntro });
|
||||
saveConversationHistory();
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate new introduction using LLM
|
||||
const introDiv = document.createElement('div');
|
||||
introDiv.style.cssText = 'position: relative; margin-bottom: 10px; padding: 10px; border-radius: 5px; background: rgba(0,100,200,0.1); border-left: 4px solid #0066cc;';
|
||||
introDiv.innerHTML = '<p><strong>🤖 Hermes:</strong> <em>Analyzing this page and preparing a personalized introduction...</em></p>';
|
||||
chatBox.appendChild(introDiv);
|
||||
|
||||
try {
|
||||
const prompt = `You are Hermes, a large language model from Nous Research. Write a friendly 2-paragraph introduction for yourself when embedded on this webpage. Be specific about this page's content and identify 2-3 key takeaways. Keep it conversational and helpful.
|
||||
|
||||
Page Title: ${pageTitle}
|
||||
Page URL: ${pageUrl}
|
||||
Page Content: ${pageContent.substring(0, 2000)}
|
||||
|
||||
Format: Start with "Greetings! I'm Hermes..." and make it sound natural and engaging. Focus on what YOU can help with regarding THIS specific page.`;
|
||||
|
||||
let generatedIntro = '';
|
||||
for await (const chunk of sendMessageDirect(prompt)) {
|
||||
generatedIntro += chunk;
|
||||
// Update display in real-time
|
||||
introDiv.innerHTML = `<p><strong>🤖 Hermes:</strong> ${generatedIntro}</p>`;
|
||||
}
|
||||
|
||||
// Add to chat history and save
|
||||
chatHistory.push({ role: "assistant", content: generatedIntro });
|
||||
saveConversationHistory();
|
||||
|
||||
// Cache the generated introduction
|
||||
localStorage.setItem(cacheKey, generatedIntro);
|
||||
|
||||
chatBox.scrollTop = chatBox.scrollHeight;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error generating introduction:', error);
|
||||
introDiv.innerHTML = '<p><strong>🤖 Hermes:</strong> Greetings! I\'m Hermes, ready to help you with anything on this page or beyond!</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function displayIntroduction(introText) {
|
||||
const introDiv = document.createElement('div');
|
||||
introDiv.style.cssText = 'position: relative; margin-bottom: 10px; padding: 10px; border-radius: 5px; background: rgba(0,100,200,0.1); border-left: 4px solid #0066cc;';
|
||||
introDiv.innerHTML = `<p><strong>🤖 Hermes:</strong> ${introText}</p>`;
|
||||
chatBox.appendChild(introDiv);
|
||||
chatBox.scrollTop = chatBox.scrollHeight;
|
||||
}
|
||||
|
||||
// Direct LLM call for introduction generation (doesn't add to chat history)
|
||||
async function* sendMessageDirect(message) {
|
||||
const selectedModel = modelSelect.value || MODEL;
|
||||
const modelInfo = modelRegistry[selectedModel];
|
||||
const endpoint = modelInfo ? modelInfo.url : VLLM_ENDPOINTS[0].url;
|
||||
const modelName = modelInfo ? modelInfo.modelName : MODEL;
|
||||
|
||||
const response = await fetch(`${endpoint}/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: modelName,
|
||||
messages: [{ role: "user", content: message }],
|
||||
temperature: 0.7,
|
||||
max_tokens: 300,
|
||||
stream: true
|
||||
}),
|
||||
});
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let buffer = '';
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, { stream: true });
|
||||
const lines = buffer.split('\n');
|
||||
|
||||
for (let i = 0; i < lines.length - 1; i++) {
|
||||
const line = lines[i].trim();
|
||||
if (line.startsWith('data: ')) {
|
||||
const jsonData = line.slice(6);
|
||||
if (jsonData === '[DONE]') continue;
|
||||
|
||||
try {
|
||||
const parsedData = JSON.parse(jsonData);
|
||||
const content = parsedData.choices[0].delta.content;
|
||||
if (content) {
|
||||
yield content;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer = lines[lines.length - 1];
|
||||
}
|
||||
}
|
||||
addHermesIntroduction();
|
||||
|
||||
// Create input area
|
||||
const inputArea = document.createElement('div');
|
||||
if (USE_CUSTOM_STYLING) {
|
||||
|
|
@ -1447,7 +1577,7 @@ function openHermesModal() {
|
|||
const messageInput = document.createElement('input');
|
||||
messageInput.type = 'text';
|
||||
messageInput.id = 'modal-user-input';
|
||||
messageInput.placeholder = 'Ask Hermes anything...';
|
||||
messageInput.placeholder = '💬 Chat with Hermes about this page, code, ideas, or anything! Your AI companion awaits...';
|
||||
messageInput.style.cssText = `
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue