readability
This commit is contained in:
parent
ac30a9a5b9
commit
5ec2d23542
2 changed files with 27 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
|
27
index.js
27
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!");
|
||||
};
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue