From cb880f9bc151cd99b36c4fa96ad093c8968f9090 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Fri, 5 May 2023 20:49:29 +0200 Subject: [PATCH] Fix Caching web reading the web: Append last message rather than add to the conversation. --- llamabot.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/llamabot.js b/llamabot.js index d5618a6..4c040c4 100644 --- a/llamabot.js +++ b/llamabot.js @@ -217,7 +217,7 @@ async function generateResponse(conversation, message) { let plainTextContent = $('
').html(pageContent).text().trim().replace(/[\r\n\t]+/g, ' '); const codePattern = /\/\/|\/\*|\*\/|\{|\}|\[|\]|\bfunction\b|\bclass\b|\b0x[0-9A-Fa-f]+\b|\b0b[01]+\b/; const isCode = codePattern.test(plainTextContent); - + if (isCode) { plainTextContent = plainTextContent.replace(codePattern, ''); } @@ -230,12 +230,12 @@ async function generateResponse(conversation, message) { } response += `URL: ${url}`; - // Append bot message to conversation history - conversation.messages.push({ - role: 'user', - content: "Data from the page is: " + response, - }); + // Get the index of the last message in the array + const lastMessageIndex = conversation.messages.length - 1; + // Append a new line and the new content to the existing content of the last message + conversation.messages[lastMessageIndex].content += "\n" + response; + console.log("A URL was provided, response: " + response) } catch (err) {