ai-brain-2/brain.mjs

74 lines
2.2 KiB
JavaScript
Raw Normal View History

import { ConsciousnessSimulator } from './brainapi.mjs';
import readline from 'readline';
class ConsciousnessApp {
constructor() {
this.simulator = new ConsciousnessSimulator();
2025-02-08 03:36:37 +00:00
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;
this.activityTimeout = null;
this.rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
}
// Function to simulate user talking
async userTalks(input) {
const reply = await this.simulator.generateThoughtAndChat(input);
2025-02-08 03:58:07 +00:00
console.log("<User>: " + input);
console.log("<Bot>: " + reply);
}
2025-02-08 03:58:07 +00:00
async userTalks(input) {
const reply = await this.simulator.generateThoughtAndChat(input);
console.log("<User>: " + input);
console.log("<Bot>: " + reply);
}
2025-02-08 03:58:07 +00:00
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;
2025-02-08 03:36:37 +00:00
2025-02-08 03:58:07 +00:00
// Wait for the random interval (non-blocking)
await new Promise(resolve => setTimeout(resolve, intervalTime));
2025-02-08 03:58:07 +00:00
await this.simulator.simulateConsciousness();
}
}
2025-02-08 03:58:07 +00:00
async asker() {
while (true) {
await rl.question('<Query>: ', (query) => {
userTalks(query)
});
}
}
2025-02-08 03:58:07 +00:00
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;
2025-02-08 03:58:07 +00:00
// Wait for the random interval (non-blocking)
await new Promise(resolve => setTimeout(resolve, intervalTime));
2025-02-08 03:36:37 +00:00
2025-02-08 03:58:07 +00:00
// 50% chance to execute the function
if (Math.random() < 0.5) {
await this.simulator.updateIntentions();
}
2025-02-08 03:36:37 +00:00
}
2025-02-08 03:33:18 +00:00
}
}
async function main() {
2025-02-08 03:58:07 +00:00
let minibrain = new ConsciousnessApp()
await this.simulator.startDreaming();
intentUpdater()
thinker()
asker()
}
2025-02-08 03:58:44 +00:00
main().catch(e => console.error(e))