From 5ec2d23542e0b912411d5461cbf0919f12615a04 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Tue, 23 Aug 2022 13:22:26 -0400 Subject: [PATCH] readability --- README.md | 8 +++++++- index.js | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 87c9864..776bb1c 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,14 @@ List of directories and files created by the project and its dependencies: - `storage.json` - `training-matrix.txt` -#### commands +#### Commands +The bot has several commands: + +```text +► generate ⇢ Generates a message in the room. +► train ⇢ Trains the AI's mini GPT-2 model. +``` ### Setup diff --git a/index.js b/index.js index 02d4629..e9e4450 100644 --- a/index.js +++ b/index.js @@ -11,13 +11,13 @@ AutojoinRoomsMixin.setupOnClient(client); client.start().then(() => console.log(`Client has started!\n`)); let messageCounter = 0; -let trainCounter = 0; +let trainingCounter = 0; client.on("room.message", (roomId, event) => { if (!event["content"] || event["sender"] === config.user) return; ++messageCounter; - ++trainCounter; + ++trainingCounter; let userMessage = event["content"]["body"].split(" "); if (userMessage[0].startsWith(config.prefix)) { @@ -28,12 +28,15 @@ client.on("room.message", (roomId, event) => { }); }; - // ? send message every N messages if big enough dataset is present - if ((!(messageCounter % config.frequency) && !(lineCount(config.file) < config.size)) || userMessage[0] === "speak") { + // ? send message if: + // ? - enough messages have been sent + // ? - commanded + if (!(messageCounter % config.frequency) || userMessage[0] === "speak") { console.log("Generating message..."); userMessage.shift() const options = { args: ['generate'] }; + PythonShell.run(pyFile, options, (err, message) => { if (err) throw err; client.sendText(roomId, message.toString()); @@ -41,12 +44,22 @@ client.on("room.message", (roomId, event) => { }); // ? send generated message to room }; - if (trainCounter >= config.retrain || userMessage[0] === "train") { + // ? retrain if: + // ? - enough message have been sent + // ? - commanded + if (trainingCounter >= config.retrain || userMessage[0] === "train") { console.log("Retraining the AI..."); + client.sendText(roomId, "Retraining the AI..."); - trainCounter = 0; - // TODO: exec training function + trainingCounter = 0; + const options = { args: ['train'] }; + + PythonShell.run(pyFile, options, (err, message) => { + if (err) throw err; + console.log(message.toString()); + }); console.log("Training finished!"); + client.sendText(roomId, "Training finished!"); }; });