Update brain.mjs
This commit is contained in:
parent
33cdc3c565
commit
9aab5125ce
1 changed files with 20 additions and 5 deletions
23
brain.mjs
23
brain.mjs
|
@ -4,7 +4,7 @@ import readline from 'readline';
|
|||
class ConsciousnessApp {
|
||||
constructor() {
|
||||
this.simulator = new ConsciousnessSimulator();
|
||||
this.ollama = this.simulator.createOllamaValue(); //init ollama @ baked-in localhost/default port
|
||||
this.ollama = this.simulator.createOllamaValue("https://ollama-api.nodemixaholic.com"); // init ollama @ baked-in localhost/default port
|
||||
this.isActive = true; // User starts active
|
||||
this.lastActiveTime = Date.now();
|
||||
this.dreamTimeout = null;
|
||||
|
@ -33,13 +33,25 @@ class ConsciousnessApp {
|
|||
|
||||
// Function to handle activity check
|
||||
handleActivity() {
|
||||
this.lastActiveTime = Date.now();
|
||||
if (!this.isActive) {
|
||||
const currentTime = Date.now();
|
||||
const elapsedTime = currentTime - this.lastActiveTime;
|
||||
|
||||
// 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(); // Start activity routines again
|
||||
this.initiateActivityRoutine(); // Resume activity checks
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,9 +104,12 @@ class ConsciousnessApp {
|
|||
});
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue