Update brain.mjs
This commit is contained in:
parent
aba73dee8b
commit
75da90efbf
1 changed files with 31 additions and 24 deletions
55
brain.mjs
55
brain.mjs
|
@ -13,6 +13,7 @@ class ConsciousnessApp {
|
|||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
this.asking = false; // Track if a question is being asked
|
||||
}
|
||||
|
||||
// Function to simulate user talking
|
||||
|
@ -22,12 +23,6 @@ class ConsciousnessApp {
|
|||
console.log("<Bot>: " + reply);
|
||||
}
|
||||
|
||||
async userTalks(input) {
|
||||
const reply = await this.simulator.generateThoughtAndChat(input);
|
||||
console.log("<User>: " + input);
|
||||
console.log("<Bot>: " + reply);
|
||||
}
|
||||
|
||||
async thinker() {
|
||||
while (true) {
|
||||
// Generate random interval between 7 and 15 minutes (in milliseconds)
|
||||
|
@ -37,22 +32,29 @@ class ConsciousnessApp {
|
|||
await new Promise(resolve => setTimeout(resolve, intervalTime));
|
||||
|
||||
await this.simulator.simulateConsciousness();
|
||||
}
|
||||
}
|
||||
}
|
||||
asking = false
|
||||
|
||||
// Non-blocking question asking function
|
||||
async asker() {
|
||||
while (true) {
|
||||
if (asking == false) {
|
||||
asking = true
|
||||
await this.rl.question('<Query>: ', (query) => {
|
||||
userTalks(query)
|
||||
asking = false
|
||||
});
|
||||
if (!this.asking) {
|
||||
this.asking = true;
|
||||
await this.askQuestion();
|
||||
this.asking = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function for asking questions
|
||||
async askQuestion() {
|
||||
return new Promise((resolve) => {
|
||||
this.rl.question('<Query>: ', (query) => {
|
||||
this.userTalks(query).then(resolve); // Call userTalks and resolve when done
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async intentUpdater() {
|
||||
while (true) {
|
||||
// Generate random interval between 7 and 15 minutes (in milliseconds)
|
||||
|
@ -65,15 +67,20 @@ class ConsciousnessApp {
|
|||
if (Math.random() < 0.5) {
|
||||
await this.simulator.updateIntentions();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async function main() {
|
||||
let minibrain = new ConsciousnessApp()
|
||||
await minibrain.simulator.startDreaming();
|
||||
minibrain.intentUpdater()
|
||||
minibrain.thinker()
|
||||
minibrain.asker()
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(e => console.error(e))
|
||||
async function main() {
|
||||
const minibrain = new ConsciousnessApp();
|
||||
await minibrain.simulator.startDreaming();
|
||||
|
||||
// Run all asynchronous functions concurrently
|
||||
await Promise.all([
|
||||
minibrain.intentUpdater(),
|
||||
minibrain.thinker(),
|
||||
minibrain.asker()
|
||||
]);
|
||||
}
|
||||
|
||||
main().catch(e => console.error(e));
|
||||
|
|
Loading…
Reference in a new issue