diff --git a/llamabot.js b/llamabot.js
index 6441187..9c8dffb 100644
--- a/llamabot.js
+++ b/llamabot.js
@@ -214,16 +214,20 @@ async function generateResponse(conversation, message) {
}
if (pageContent) {
const MAX_CONTENT_LENGTH = process.env.MAX_CONTENT_LENGTH;
- let plainTextContent = $('
').html(pageContent).text().trim().replace(/[\r\n\t]+/g, ' ');
-
+ let plainTextContent = $('
').html(pageContent).text().trim().replace(/[\r\n]+/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, '');
+ }
+ // Remove anything enclosed in brackets
+ plainTextContent = plainTextContent.replace(/ *\([^)]*\) */g, '');
if (plainTextContent.length > MAX_CONTENT_LENGTH) {
plainTextContent = plainTextContent.substring(0, MAX_CONTENT_LENGTH) + '...';
- response += `Content: ${plainTextContent.trim()}`;
- } else {
- response += `Content: ${plainTextContent.trim()}`;
}
+ response += `Content: ${plainTextContent.trim().replace(/[\n\r]+| +/g, ' ')}`;
}
-
response += `URL: ${url}`;
// Append bot message to conversation history