Matrix bot that generates messages based off of messages of other users using a neural network.
 
 
Go to file
array-in-a-matrix 9e25b346c8 train longer 2023-02-06 13:54:53 -05:00
.gitignore ignore AI related files 2022-08-15 23:38:00 -04:00
LICENSE Initial commit 2022-08-15 00:50:58 -04:00
README.md Merge branch 'master' of https://git.arrayinamatrix.xyz/array-in-a-matrix/text-gen-bot 2023-02-03 11:48:57 -05:00
example.config.json removed size variable 2022-08-23 13:39:54 -04:00
generate.py refactor make the code actually somewhat bearable 2023-02-03 11:29:28 -05:00
index.js Update 'index.js' 2023-02-03 18:15:47 -05:00
package.json now using pythonshell lib 2022-08-22 01:55:10 -04:00
pnpm-lock.yaml now using pythonshell lib 2022-08-22 01:55:10 -04:00
train.py train longer 2023-02-06 13:54:53 -05:00

README.md

text-gen-bot

Matrix bot that generates messages based off of messages of other users using a neural network. The first Matrix AI? Featured on TWIM!

Note: Project is still being developed and some functionality is not fully implemented yet.

Table of content

Usage

First install the needed using the instructions here. 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 section of this document. To obtain the token of an account follow the instructions here.

Once the config file has been populated with valid data, execute the index.js file (Warning: executing for the first time will be slow.).

$ node index.js
...
<some warnings show up, ignore them>
...
Client has started!
...

List of directories and files created by the project and its dependencies:

  • aitextgen/
  • node_modules/
  • trained_model/
  • aitextgen.tokenizer.json
  • storage.json
  • training-matrix.txt

Commands

The bot has several commands:

► speak       ⇢     Generates a message in the room. 
► prompt      ⇢     Generate a message using a prompt.

To train the AI, run this command:

> python3 train.py

Setup

The project is split into 2 parts index.js and textgen.py. The index.js file contains the code that interacts with the user on Matrix and sends text generated by the textgen.py file.

Install matrix-bot-sdk and python-shell (JS):

> pnpm add matrix-bot-sdk
> pnpm add python-shell

Install aitextgen (PY):

> 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 (stared below) must be supplied before usage.

► 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 (.txt file only).

► prefix        ⇢     Bot listens to commands that start with this prefix.

► frequency     ⇢     How often the bot sends a message (keep high to prevent spam).

► retrain       ⇢      The bot retrains itself after this many extra lines of messages are recorded in the text file.

Using existing messages

If you do not want to wait until the bot creates its own dataset from new messages, you can export chat history of a room easily using Element. In this case, you will need to manually remove the time stamps from the text file then place the path of the file in the file variable in the configuration file.