UNPKG

algoritms.ai

Version:

The Algoritms.AI build tools to create better and lightweight AI models with Acuuracy, Context, Frequency, Memory, Maths in Natural Language, Natural Language Processing, Probablities and Vectors.

73 lines (60 loc) 2.06 kB
const fs = require("fs"); const path = require("path"); const readline = require("readline"); // **Memory file path** const memoryFilePath = path.join(__dirname, "..", "user", "fellow_user.txt"); // **Load existing memory** function loadMemory() { if (!fs.existsSync(memoryFilePath)) return {}; const data = fs.readFileSync(memoryFilePath, "utf-8").split("\n"); let memory = {}; for (let line of data) { let match = line.match(/(.+)\s*=\s*(.+)/); if (match) { let key = match[1].trim(); let value = match[2].trim(); memory[key] = value; } } return memory; } // **Save memory to file** function saveMemory(memory) { let memoryData = Object.entries(memory) .map(([key, value]) => `${key} = ${value}`) .join("\n"); fs.writeFileSync(memoryFilePath, memoryData, "utf-8"); } // **Real-time user input (Frontend)** function memAllocFrontend() { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question("Enter something for the AI to remember: ", (input) => { let memory = loadMemory(); // Detect name input let nameMatch = input.match(/(?:my name is|I am|call me)\s+([\w\s]+)/i); if (nameMatch) { let name = nameMatch[1].trim(); memory["User"] = name; saveMemory(memory); console.log(`Memorized: User = ${name}`); } else { console.log("No memory allocated."); } rl.close(); }); } // **Backend memory storage (Predefined variables)** function memAllocBackend(variable, value) { let memory = loadMemory(); memory[variable] = value; saveMemory(memory); console.log(`Memorized: ${variable} = ${value}`); } // **Example Usage** // Uncomment to test real-time input // memAllocFrontend(); // Example of backend allocation // memAllocBackend("favoriteColor", "Blue");