Compare commits

...

4 commits

Author SHA1 Message Date
array-in-a-matrix 657990fd15 cleaned up code 2022-08-16 00:47:38 -04:00
array-in-a-matrix 31688c2dba configuration file 2022-08-16 00:39:40 -04:00
array-in-a-matrix c40df8e1e9 ignore AI related files 2022-08-15 23:38:00 -04:00
array-in-a-matrix 64e9208dc2 renamed var 2022-08-15 23:37:24 -04:00
4 changed files with 42 additions and 10 deletions

4
.gitignore vendored
View file

@ -157,8 +157,10 @@ cython_debug/
# ignore folders
node_modules
aitextgen
trained_model
# ignore files
config.json
storage.json
training-*.txt
training-*.txt
aitextgen.tokenizer.json

View file

@ -4,7 +4,7 @@ Matrix bot that generates messages based off of messages of other users using a
## Usage
First install the needed [libraries](#setup). Then copy `example.config.json` and rename it `config.json`. Replace the items in angled brackets with their respective values of the bot account (e.g. replace `<DOMAIN.TLD>` with the homeserver url like `https://matrix.org` or `https://matrix.arrayinamatrix.xyz`). You can follow the instructions [here](https://matrix.org/docs/guides/usage-of-matrix-bot-sdk#instantiation) to obtain the token of an account.
First install the needed [libraries](#setup). Then copy `example.config.json` and rename it `config.json`. Replace the items in angled brackets with their respective values of the bot account (e.g. replace `<DOMAIN.TLD>` with the homeserver url like `https://matrix.org` or `https://matrix.arrayinamatrix.xyz`). An explanation of each configurable string is located in [configurations](#configurations) section of this document. To obtain the token of an account follow the instructions [here](https://matrix.org/docs/guides/usage-of-matrix-bot-sdk#instantiation).
Once the config file has been populated with valid data, execute the `index.js` file (Warning: executing for the first time will be slow.).
@ -32,3 +32,23 @@ Install Python module:
```sh
> pip3 install aitextgen
```
## Configurations
Before a bot can be used the fields in the `config.json` file must be populated with valid information. Values in angled brackets (are stared below) must be supplied before usage.
```json
► homeserver* ⇢ URL of the bot's homeserver.
► token* ⇢ Account token used to sign in the bot.
► user* ⇢ Account's User ID.
► file ⇢ Path of file used for training the AI.
► prefix ⇢ Bot listens to commands that start with this prefix.
► frequency ⇢ How often the bot sends a message (keep low 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.
```

View file

@ -1,6 +1,9 @@
{
"baseUrl": "<DOMAIN.TLD>",
"homeserver": "<DOMAIN.TLD>",
"token": "<TOKEN>",
"userId": "@<USER>:<DOMAIN.TLD>",
"prefix": "!"
"user": "@<USER>:<DOMAIN.TLD>",
"file": "training-matrix.txt",
"prefix": "!",
"frequency": "25",
"size": "5000"
}

View file

@ -3,7 +3,7 @@ import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matri
import fs from "fs";
const storage = new SimpleFsStorageProvider("storage.json");
const client = new MatrixClient(config.baseUrl, config.token, storage);
const client = new MatrixClient(config.homeserver, config.token, storage);
AutojoinRoomsMixin.setupOnClient(client)
client.start().then(() => console.log(`Client has started!\n`));
@ -12,16 +12,23 @@ let messageCounter = 0;
// ? event listener: logs messages sent into file
client.on("room.message", (roomId, event) => {
if (!event["content"] || event["sender"] === config.userId) return;
messageCounter = messageCounter + 1;
if (!event["content"] || event["sender"] === config.user) return;
++messageCounter;
fs.appendFile('training-matrix.txt', event["content"]["body"] + "\n", function (err) {
if (err) throw err;
console.log(messageCounter + "\t" + event["content"]["body"]);
// console.log(messageCounter + "\t" + event["content"]["body"]);
});
if (lineCount(config.file) < config.size) return; // ? don't start generating messages until a big enough dataset is present
// TODO: train AI every Nth message?
// ? send message every N messages using the training data
if (!(messageCounter % 7)) {
if (!(messageCounter % config.frequency)) {
console.log("Generating message...");
client.sendText(roomId, "Hello, World!"); // TODO: exec py function to gen message str
};
});
function lineCount(text) {
return fs.readFileSync(text).toString().split("\n").length - 1;
}