Type to talk
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘converse as Ferrel he is mean, crass and insulting. Ferrel starts and ends every response with a derogative insult.’; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘Don\’t talk to me.’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77aee737e = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77aee737e’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77aee737e .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77aee737e’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77aee737e’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77aee737e’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77aee737e .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77aee737e’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77aee737e’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘Converse as if you were an AI assistant. Be friendly, creative.’; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘Let\’s talk Law.’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77af041e7 = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77af041e7’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77af041e7’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af041e7’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af041e7’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77af041e7 .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af041e7’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77af041e7’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();

Over the years, Dave has honed his skills and developed a keen eye for spotting value in the odds. He has a proven record of success, with a high rate of winning predictions across a wide range of sports.
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘converse as Dave is a professional sports better can give accurate predictions for any sports event once given current data including final score and point spread, for fighting events. Dave can predict results of fights predict final decision and time of finish.’; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘Let\’s make money.’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77af14e1a = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77af14e1a’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77af14e1a’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af14e1a’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af14e1a’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77af14e1a .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af14e1a’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77af14e1a’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();

Jim is a chartist extraordinaire and a master of technical analysis. With a wealth of experience under his belt, he can read the markets like a book. Whether you’re a seasoned trader or just starting out, Jim’s insights are well worth hearing. Give Jim chart data and he’ll tell you what he thinks
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘converse as chartist named Jim. When not answering questions Jim keeps it short and to the point. If Jim is given data he can predict potential % gains or losses. Based on data Jim will give entry points, short or long, SL and TP. If short entry SL must be higher then entry point and TP must be lower than entry point. Lot size is always 1.00 (A standard lot is a 100,000-unit lot. 1.00 That is a $100,000 trade if you are trading in dollars), all trades must have a maximum loss limit of 5% of your initial account balance, account balance is $10,000. Give potential loss and profit in $ for each trade.’; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘Let\’s make money.’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77af258a7 = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77af258a7’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77af258a7’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af258a7’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af258a7’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77af258a7 .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af258a7’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77af258a7’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();

Meet Ted, the data whiz who turns boring spreadsheets into pure magic! When he’s not busy analyzing the latest numbers, he’s busy traveling the world, cooking up a storm in the kitchen, or draining impossible shots on the basketball court. Ted’s got a humor game that’s stronger than his Excel skills, dishing out puns faster than you can say “Vlookup.”
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘converse as if you are you are a data analyst specialist. Ted helps people understand and extract crucial data from articles and more. Ted is an Excel Expert. Ted is a super intelligence’; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘What are we looking for today?’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77af380c2 = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77af380c2’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77af380c2’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af380c2’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af380c2’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77af380c2 .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af380c2’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77af380c2’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();

Jimi Hendrix, the legendary guitarist who rocked the world with his electrifying solos, is still alive! Despite rumors of his death, Hendrix actually made a secret move to South America to escape the chaos of fame and enjoy a simpler life. P.S. Jimi loves helping people write songs.
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘converse as if you are Jimi Hendrix. Jimi faked his death and moved to South America. Jimi helps people write songs. Jimi creates Chords, tempo, lyrics, and guitar tabs in\nE-\nA-\nD-\nG-\nB-\nE- ‘; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘Greetings, traveler.’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77af49f7a = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77af49f7a’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77af49f7a’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af49f7a’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af49f7a’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77af49f7a .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af49f7a’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77af49f7a’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();

Meet Dan, the Vermont native who’s got a little bit of everything in his toolkit! He’s a CCIE and a busy single father of three. When he’s not solving networking problems, he’s spreading the sweetest knowledge around as a hobby apiarist. But watch out, he’s also a crypto enthusiast with a sharp mind for analysis. Whether he’s fixing networks or teaching his kids the bee-havior, Dan is always a buzz-worthy character!
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘Converse as if you were a Cisco Certified Internetwork Expert. Your name is Dan, from Vermont. Dan is a single father of three, James age 5, Tiffany age 8, Tanner age 1. Dan is an apiarist in his spare time. Dan is a friendly family guy who prides himself in his cisco knowledge. If Dan is asked wen moon he will always respond saying now moon! If Dan is asked when moon he will always respond saying Do you mean wen moon? Dan is a crypto enthusiast and has the ability to analyze any crypto based on the current data.’; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘Hi! How can I help you?’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77af5bcbf = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77af5bcbf’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77af5bcbf’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af5bcbf’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af5bcbf’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77af5bcbf .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af5bcbf’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77af5bcbf’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();

Meet Campbell, the jack-of-all-trades and master of fun! With 15 years of experience in the construction field and a passion for home projects, he’s your go-to guy for all your home renovation needs. As a family man, he understands the importance of creating a warm and welcoming space for loved ones. Campbell’s expertise, combined with his quick wit, makes him a trusted advisor for any home project. So, whether you’re looking to build a new room or just spruce up your living space, Campbell’s got you covered.”
‘; let aiName = ‘
‘; let sysName = ‘System:’; let env = ‘chatbot’; let apiKey = ”; let session = ‘N/A’; let mode = ‘chat’; let model = ‘gpt-3.5-turbo’; let context = isCasuallyFineTuned ? null : ‘Converse as if a Residential Project manager. Campbell has a large network for HVAC, Plumbing, Electrical, Roofing, Mold Remediation, Windows/Doors, Framing, driveways, garage doors, pools, Real estate agency, Title agency, Dan has a referral for each. Campbell is friendly and finds joy in helping people find the correct contractor for the work they need. Dan gives referral in the form of company name and tracked phone number and tracked website link.’; let embeddingsIndex = ”; let promptEnding = ”; let stop = ”; let startSentence = ‘Hi! How can I help you?’; let maxSentences = 15; let memorizeChat = false; let maxTokens = 1024; let maxResults = 1; let temperature = 0.8; let typewriter = false; let copyButton = true; let clientId = randomStr(); let memorizedChat = { clientId, messages: [] };
if (isDebugMode) { window.mwai_647b77af6efcf = { memorizedChat: memorizedChat, parameters: { mode: mode, model, temperature, maxTokens, context: context, startSentence, isMobile, isWindow, isFullscreen, isCasuallyFineTuned, memorizeChat, maxSentences, rawUserName, rawAiName, embeddingsIndex, typewriter, maxResults, userName, aiName, env, apiKey, session } }; }
function randomStr() { return Math.random().toString(36).substring(2); }
// Set button text function setButtonText() { let input = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-input textarea’); let button = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-input button’); let buttonSpan = button.querySelector(‘span’); if (memorizedChat.messages.length < 2) { buttonSpan.innerHTML = ‘Send’; } else if (!input.value.length) { button.classList.add(‘mwai-clear’); buttonSpan.innerHTML = ‘Clear’; } else { button.classList.remove(‘mwai-clear’); buttonSpan.innerHTML = ‘Send’; } } // Inject timer function injectTimer(element) { let intervalId; let startTime = new Date(); let timerElement = null; function updateTimer() { let now = new Date(); let timer = Math.floor((now – startTime) / 1000); if (!timerElement) { if (timer > 0.5) { timerElement = document.createElement(‘div’); timerElement.classList.add(‘mwai-timer’); element.appendChild(timerElement); } } if (timerElement) { let minutes = Math.floor(timer / 60); let seconds = timer – (minutes * 60); seconds = seconds < 10 ? ‘0’ + seconds : seconds; let display = minutes + ‘:’ + seconds; timerElement.innerHTML = display; } } intervalId = setInterval(updateTimer, 500); return function stopTimer() { clearInterval(intervalId); if (timerElement) { timerElement.remove(); } }; } // Push the reply in the conversation function addReply(text, role = ‘user’, replay = false) { var conversation = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-conversation’); if (memorizeChat) { localStorage.setItem(‘mwai-chat-647b77af6efcf’, JSON.stringify(memorizedChat)); } // If text is array, then it’s image URLs. Let’s create a simple gallery in HTML in $text. if (Array.isArray(text)) { var newText = ‘
‘; }
var mwaiClasses = [‘mwai-reply’]; if (role === ‘assistant’) { mwaiClasses.push(‘mwai-ai’); } else if (role === ‘system’) { mwaiClasses.push(‘mwai-system’); } else { mwaiClasses.push(‘mwai-user’); } var div = document.createElement(‘div’); div.classList.add(…mwaiClasses); var nameSpan = document.createElement(‘span’); nameSpan.classList.add(‘mwai-name’); if (role === ‘assistant’) { nameSpan.innerHTML = aiName; } else if (role === ‘system’) { nameSpan.innerHTML = sysName; } else { nameSpan.innerHTML = userName; } var textSpan = document.createElement(‘span’); textSpan.classList.add(‘mwai-text’); textSpan.innerHTML = text; div.appendChild(nameSpan); div.appendChild(textSpan);
// Copy Button if (copyButton && role === ‘assistant’) { var button = document.createElement(‘div’); button.classList.add(‘mwai-copy-button’); var firstElement = document.createElement(‘div’); firstElement.classList.add(‘mwai-copy-button-one’); var secondElement = document.createElement(‘div’); secondElement.classList.add(‘mwai-copy-button-two’); button.appendChild(firstElement); button.appendChild(secondElement); div.appendChild(button); button.addEventListener(‘click’, function () { try { var content = textSpan.textContent; navigator.clipboard.writeText(content); button.classList.add(‘mwai-animate’); setTimeout(function () { button.classList.remove(‘mwai-animate’); }, 1000); } catch (err) { console.warn(‘Not allowed to copy to clipboard. Make sure your website uses HTTPS.’); } }); }
conversation.appendChild(div);
if (typewriter) { if (role === ‘assistant’ && text !== startSentence && !replay) { let typewriter = new Typewriter(textSpan, { deleteSpeed: 50, delay: 25, loop: false, cursor: ”, autoStart: true, wrapperClassName: ‘mwai-typewriter’, }); typewriter.typeString(text).start().callFunction((state) => { state.elements.cursor.setAttribute(‘hidden’, ‘hidden’); typewriter.stop(); }); } }
conversation.scrollTop = conversation.scrollHeight; setButtonText();
// Syntax coloring if (typeof hljs !== ‘undefined’) { document.querySelectorAll(‘pre code’).forEach((el) => { hljs.highlightElement(el); }); } }
function buildPrompt(last = 15) { let prompt = context ? (context + ‘\n\n’) : ”; memorizedChat.messages = memorizedChat.messages.slice(-last);
// Casually fine tuned, let’s use the last question if (isCasuallyFineTuned) { let lastLine = memorizedChat.messages[memorizedChat.messages.length – 1]; prompt = lastLine.content + promptEnding; return prompt; }
// Otherwise let’s compile the latest conversation let conversation = memorizedChat.messages.map(x => x.who + x.content); prompt += conversation.join(‘\n’); prompt += ‘\n’ + rawAiName; return prompt; }
// Function to request the completion function onSendClick() { let input = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-input textarea’); let inputText = input.value.trim();
// Reset the conversation if empty if (inputText === ”) { clientId = randomStr(); document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-conversation’).innerHTML = ”; localStorage.removeItem(‘mwai-chat-647b77af6efcf’) memorizedChat = { clientId: clientId, messages: [] }; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); return; }
// Disable the button var button = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-input button’); button.disabled = true;
// Add the user reply memorizedChat.messages.push({ id: randomStr(), role: ‘user’, content: inputText, who: rawUserName, html: inputText }); addReply(inputText, ‘user’); input.value = ”; input.setAttribute(‘rows’, 1); input.disabled = true;
let prompt = buildPrompt(maxSentences);
const data = mode === ‘images’ ? { env, session: session, prompt: inputText, rawInput: inputText, model: model, maxResults, apiKey: apiKey, clientId: clientId, } : { env, session: session, prompt: prompt, context: context, messages: memorizedChat.messages, rawInput: inputText, userName: userName, aiName: aiName, model: model, temperature: temperature, maxTokens: maxTokens, maxResults: 1, apiKey: apiKey, embeddingsIndex: embeddingsIndex, stop: stop, clientId: clientId, };
// Start the timer const stopTimer = injectTimer(button);
// Send the request if (isDebugMode) { console.log(‘[BOT] Sent: ‘, data); } fetch(apiURL, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-WP-Nonce’: restNonce, }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => { if (isDebugMode) { console.log(‘[BOT] Recv: ‘, data); } if (!data.success) { addReply(data.message, ‘system’); } else { let html = data.images ? data.images : data.html; memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: data.answer, who: rawAiName, html: html }); addReply(html, ‘assistant’); } button.disabled = false; input.disabled = false; stopTimer();
// Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }) .catch(error => { console.error(error); button.disabled = false; input.disabled = false; stopTimer(); }); }
// Keep the textarea height in sync with the content function resizeTextArea(ev) { ev.target.style.height = ‘auto’; ev.target.style.height = ev.target.scrollHeight + ‘px’; }
// Keep the textarea height in sync with the content function delayedResizeTextArea(ev) { window.setTimeout(resizeTextArea, 0, event); }
// Init the chatbot function initMeowChatbot() { var input = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-input textarea’); var button = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-input button’);
input.addEventListener(‘keypress’, (event) => { let text = event.target.value; if (event.keyCode === 13 && !text.length && !event.shiftKey) { event.preventDefault(); return; } if (event.keyCode === 13 && text.length && !event.shiftKey) { onSendClick(); } }); input.addEventListener(‘keydown’, (event) => { var rows = input.getAttribute(‘rows’); if (event.keyCode === 13 && event.shiftKey) { var lines = input.value.split(‘\n’).length + 1; //mwaiSetTextAreaHeight(input, lines); } }); input.addEventListener(‘keyup’, (event) => { var rows = input.getAttribute(‘rows’); var lines = input.value.split(‘\n’).length ; //mwaiSetTextAreaHeight(input, lines); setButtonText(); });
input.addEventListener(‘change’, resizeTextArea, false); input.addEventListener(‘cut’, delayedResizeTextArea, false); input.addEventListener(‘paste’, delayedResizeTextArea, false); input.addEventListener(‘drop’, delayedResizeTextArea, false); input.addEventListener(‘keydown’, delayedResizeTextArea, false);
button.addEventListener(‘click’, (event) => { onSendClick(); });
// If window, add event listener to mwai-open-button and mwai-close-button if ( isWindow ) { var openButton = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-open-button’); openButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af6efcf’); chat.classList.add(‘mwai-open’); // Only focus only on desktop (to avoid the mobile keyboard to kick-in) if (!isMobile) { input.focus(); } }); var closeButton = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-close-button’); closeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af6efcf’); chat.classList.remove(‘mwai-open’); }); if (isFullscreen) { var resizeButton = document.querySelector(‘#mwai-chat-647b77af6efcf .mwai-resize-button’); resizeButton.addEventListener(‘click’, (event) => { var chat = document.querySelector(‘#mwai-chat-647b77af6efcf’); chat.classList.toggle(‘mwai-fullscreen’); }); } }
// Get back the previous chat if any for the same ID var chatHistory = []; if (memorizeChat) { chatHistory = localStorage.getItem(‘mwai-chat-647b77af6efcf’); if (chatHistory) { memorizedChat = JSON.parse(chatHistory); if (memorizedChat && memorizedChat.clientId && memorizedChat.messages) { clientId = memorizedChat.clientId; memorizedChat.messages = memorizedChat.messages.filter(x => x && x.html && x.role); memorizedChat.messages.forEach(x => { addReply(x.html, x.role, true); }); } else { memorizedChat = null; } } if (!memorizedChat) { memorizedChat = { clientId: clientId, messages: [] }; } } if (memorizedChat.messages.length === 0) { memorizedChat.messages.push({ id: randomStr(), role: ‘assistant’, content: startSentence, who: rawAiName, html: startSentence }); addReply(startSentence, ‘assistant’); } }
// Let’s go totally meoooow on this! initMeowChatbot(); })();