Fix Caching web reading the web: Append last message rather than add to the conversation.

This commit is contained in:
Raven Scott 2023-05-05 20:49:29 +02:00 committed by MrTuxedo
parent a34a910200
commit 99ea986bbd

View File

@ -217,7 +217,7 @@ async function generateResponse(conversation, message) {
let plainTextContent = $('<div>').html(pageContent).text().trim().replace(/[\r\n\t]+/g, ' '); let plainTextContent = $('<div>').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 codePattern = /\/\/|\/\*|\*\/|\{|\}|\[|\]|\bfunction\b|\bclass\b|\b0x[0-9A-Fa-f]+\b|\b0b[01]+\b/;
const isCode = codePattern.test(plainTextContent); const isCode = codePattern.test(plainTextContent);
if (isCode) { if (isCode) {
plainTextContent = plainTextContent.replace(codePattern, ''); plainTextContent = plainTextContent.replace(codePattern, '');
} }
@ -230,12 +230,12 @@ async function generateResponse(conversation, message) {
} }
response += `URL: ${url}`; response += `URL: ${url}`;
// Append bot message to conversation history // Get the index of the last message in the array
conversation.messages.push({ const lastMessageIndex = conversation.messages.length - 1;
role: 'user',
content: "Data from the page is: " + response,
});
// 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) console.log("A URL was provided, response: " + response)
} catch (err) { } catch (err) {