Compare commits

...

4 commits

Author SHA1 Message Date
array-in-a-matrix 0e867ebbc6 fixed typo 2022-08-23 13:40:18 -04:00
array-in-a-matrix 03d928a3f0 removed size variable 2022-08-23 13:39:54 -04:00
array-in-a-matrix 4774610dad message counter for each room 2022-08-23 13:27:37 -04:00
array-in-a-matrix 5ec2d23542 readability 2022-08-23 13:22:26 -04:00
3 changed files with 35 additions and 14 deletions

View file

@ -1,6 +1,7 @@
# text-gen-bot
Matrix bot that generates messages based off of messages of other users using a neural network. The first Matrix AI?
Note: Project is still being developed and some functionality is not fully implemented yet.
## Table of content
@ -34,8 +35,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
@ -71,8 +78,6 @@ Before a bot can be used the fields in the `config.json` file must be populated
► frequency ⇢ How often the bot sends a message (keep high to prevent spam).
► size ⇢ Bot starts generating messages when the number of lines in the training file is equal to this. The greater the size, the longer bot waits before messaging but might increase message quality.
► retrain ⇢ The bot retrains itself after this many extra lines of messages are recorded in the text file.
```

View file

@ -5,6 +5,5 @@
"file": "training-matrix.txt",
"prefix": "!",
"frequency": "25",
"size": "5000",
"retrain": "10000"
}

View file

@ -10,14 +10,18 @@ const pyFile = "textgen.py";
AutojoinRoomsMixin.setupOnClient(client);
client.start().then(() => console.log(`Client has started!\n`));
let messageCounter = 0;
let trainCounter = 0;
// let messageCounter = 0;
const messageCounters = new Map(); // room ID, message count
let trainingCounter = 0;
client.on("room.message", (roomId, event) => {
if (!event["content"] || event["sender"] === config.user) return;
++messageCounter;
++trainCounter;
// ++messageCounter;
messageCounters.set(roomId, (messageCounters.get(roomId) ?? 0) + 1);
console.log(`COUNTER:\t${messageCounters.get(roomId)}\t${roomId}`);
++trainingCounter;
let userMessage = event["content"]["body"].split(" ");
if (userMessage[0].startsWith(config.prefix)) {
@ -28,12 +32,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 (!(messageCounters.get(roomId) % 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 +48,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!");
};
});