From 98f3ee3bd5321f8becb84a39e503edc6e003dba4 Mon Sep 17 00:00:00 2001 From: sneedgroup-holder Date: Sat, 8 Feb 2025 03:58:07 +0000 Subject: [PATCH] Update brain.mjs --- brain.mjs | 139 +++++++++++++++--------------------------------------- 1 file changed, 37 insertions(+), 102 deletions(-) diff --git a/brain.mjs b/brain.mjs index 8a854cd..f20c9dd 100644 --- a/brain.mjs +++ b/brain.mjs @@ -18,122 +18,57 @@ class ConsciousnessApp { // Function to simulate user talking async userTalks(input) { const reply = await this.simulator.generateThoughtAndChat(input); - console.log("User: " + input); - console.log("App: " + reply); + console.log(": " + input); + console.log(": " + reply); } - // Simulate the dreaming behavior - async startDreaming() { - if (!this.isActive) { - console.log("App is dreaming... (Inactive for 15 minutes)"); - await this.simulator.simulateConsciousness(); // Simulate self-consciousness while dreaming - await this.simulator.updateIntentions(); // Chance of updating intentions during dreaming - } + async userTalks(input) { + const reply = await this.simulator.generateThoughtAndChat(input); + console.log(": " + input); + console.log(": " + reply); } - // Function to handle activity check - handleActivity() { - const currentTime = Date.now(); - const elapsedTime = currentTime - this.lastActiveTime; + async thinker() { + while (true) { + // Generate random interval between 7 and 15 minutes (in milliseconds) + const intervalTime = Math.random() * (15 * 60 * 1000 - 7 * 60 * 1000) + 7 * 60 * 1000; - // Check if it's been more than 15 minutes of inactivity - if (elapsedTime > (15 * 60 * 1000) && this.isActive) { - this.isActive = false; - console.log("No activity for 15 minutes. Entering dream state..."); - this.simulator.setUserActive(false); // Simulate dreaming - clearTimeout(this.dreamTimeout); // Cancel any existing timeout - this.startDreaming(); // Start dreaming state - } - - // If user becomes active again - if (this.isActive === false && elapsedTime < (15 * 60 * 1000)) { - this.isActive = true; - console.log("User is active again. Waking up from dream..."); - this.simulator.setUserActive(true); // Wake up from dreaming - clearTimeout(this.dreamTimeout); // Cancel dream timeout - this.initiateActivityRoutine(); // Resume activity checks - } - } + // Wait for the random interval (non-blocking) + await new Promise(resolve => setTimeout(resolve, intervalTime)); - // Update intentions with a 50/50 chance after 7-15 minutes of activity - async checkIntentions() { - const currentTime = Date.now(); - const elapsedTime = currentTime - this.lastActiveTime; - - // 50/50 chance to update intentions every 7-15 minutes of activity - if (elapsedTime > (7 * 60 * 1000) && elapsedTime < (15 * 60 * 1000)) { - if (Math.random() > 0.5) { - console.log("Updating intentions..."); - await this.simulator.updateIntentions(); + await this.simulator.simulateConsciousness(); } - } } - // Routine to check activity every minute - initiateActivityRoutine() { - this.activityTimeout = setInterval(async () => { - const idleTime = Date.now() - this.lastActiveTime; - - if (idleTime > (15 * 60 * 1000)) { - this.isActive = false; - console.log("No activity for 15 minutes. Entering dream state..."); - this.startDreaming(); - clearInterval(this.activityTimeout); // Stop activity checks while dreaming - this.startDreamingTimeout(); - } else { - await this.checkIntentions(); - } - }, 60000); // Check every minute - } - - // Handle dream timeout (15 minutes of inactivity) - startDreamingTimeout() { - this.dreamTimeout = setTimeout(() => { - this.isActive = true; - console.log("Waking up after dreaming..."); - this.simulator.setUserActive(true); - this.initiateActivityRoutine(); // Restart activity checks - }, 15 * 60 * 1000); // Dream timeout after 15 minutes of inactivity - } - - // Start interactive conversation with the user - async startConversation() { - while (this.isActive) { - const input = await new Promise((resolve) => { - this.rl.question("You can start talking to the app. Type your message: ", resolve); + async asker() { + while (true) { + await rl.question(': ', (query) => { + userTalks(query) }); - - this.handleActivity(); // Update activity when the user types - - if (input.trim() !== '') { // Only respond if the input is not empty - await this.userTalks(input); // App replies to user input - } } } - async start() { - await this.simulator.simulateConsciousness(); // Simulate initial consciousness - this.initiateActivityRoutine(); // Start activity and dream checks - this.startConversation(); // Start the interactive conversation - } -} + async intentUpdater() { + while (true) { + // Generate random interval between 7 and 15 minutes (in milliseconds) + const intervalTime = Math.random() * (15 * 60 * 1000 - 7 * 60 * 1000) + 7 * 60 * 1000; -// Main app function + // Wait for the random interval (non-blocking) + await new Promise(resolve => setTimeout(resolve, intervalTime)); + + // 50% chance to execute the function + if (Math.random() < 0.5) { + await this.simulator.updateIntentions(); + } + } + } +} async function main() { - const app = new ConsciousnessApp(); - await app.start(); - - // Optional: Simulate the user becoming inactive after 10 seconds and then becoming active again - setTimeout(() => { - app.isActive = false; - app.simulator.setUserActive(false); // User inactive (dreaming) - console.log("User is inactive... dreaming..."); - }, 10000); - - // Simulate user becoming active again after 30 seconds - setTimeout(() => { - app.handleActivity(); - }, 30000); + let minibrain = new ConsciousnessApp() + await this.simulator.startDreaming(); + intentUpdater() + thinker() + asker() } -main().catch(console.error); +main().catch(e => console.erro(e)) \ No newline at end of file