Compare commits
4 commits
ac30a9a5b9
...
0e867ebbc6
Author | SHA1 | Date | |
---|---|---|---|
0e867ebbc6 | |||
03d928a3f0 | |||
4774610dad | |||
5ec2d23542 |
13
README.md
13
README.md
|
@ -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.
|
||||
```
|
||||
|
||||
|
|
|
@ -5,6 +5,5 @@
|
|||
"file": "training-matrix.txt",
|
||||
"prefix": "!",
|
||||
"frequency": "25",
|
||||
"size": "5000",
|
||||
"retrain": "10000"
|
||||
}
|
||||
|
|
35
index.js
35
index.js
|
@ -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!");
|
||||
};
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue