Talk to ChatGPT via any Matrix client!
A Matrix bot that uses waylaidwanderer/node-chatgpt-api to access the unofficial ChatGPT API.
The bot won't work as expected out of the box and there is no known free model which can be used:
- The
CHATGPT_MODEL
environment can be used to set the model - as of writing the default uses a model of ChatGPT from late 2022 which is not working at the moment and we do not know if and when this will change. However, you can change theCHATGPT_MODEL
env totext-davinci-003
or any other of the supported models. Keep in mind that that these alternative models are not free and will cost you OpenAI credits. - Check the waylaidwanderer/node-chatgpt-api repository for any updates on this.
- Create a room
- Add the bot
- Start chatting.
- Shows typing indicator as ChatGPT is thinking!
- Supports encryption
- Stores context for ChatGPT conversations
Create a copy of the example .env
file
cp .env.example .env
Adjust all required settings in the .env
file before running. Optional settings can also be adjusted later.
- You need a Matrix account on Matrix.org (or any other server) for the bot user.
- By default, anyone that knows the name of your bot can invite it to rooms or chat with it.
- Restrict access with
MATRIX_BLACKLIST
orMATRIX_WHITELIST
- Restrict access with
MATRIX_BLACKLIST_ROOMS
orMATRIX_WHITELIST_ROOMS
- When using a self-hosted setup, you could wildcard all your users with
MATRIX_WHITELIST=:yourhomeserver.example
.
- You need to have an account at openai.com.
- Create a API Key. Then, set
OPENAI_API_KEY
in your.env
file - You might want to change to chat-model by setting the
CHATGPT_MODEL
in your.env
file. - The model currently defaults to
text-chat-davinci-002-20221122
. - Check the node-chatgpt-api repository to keep track of the models.
- Set
MATRIX_BOT_USERNAME
- Set
MATRIX_BOT_PASSWORD
(you can remove this later if you want) - Run the app using one of the methods below.
- Copy
MATRIX_ACCESS_TOKEN
from the output. - Set
MATRIX_ACCESS_TOKEN
, you can now removeMATRIX_BOT_PASSWORD
.
Note: Doing any of the following can cause issues with encryption later on:
- Using this token with any other client.
- Using an access token extracted via Element.
- Deleting the storage folder.
- Switching between environments (e.g. Docker or no Docker)
There are multiple ways to run this bot. The easiest way is to run it within docker.
This is the recommended way to run this project. It will use the latest stable release.
docker run -it -v storage:/storage --env-file=./.env --name matrix-chatgpt-bot ghcr.io/matrixgpt/matrix-chatgpt-bot:latest
or to build locally from the latest unstable release (only do this if you have a good reason):
docker build . -t matrix-chatgpt-bot
docker run -it -v storage:/storage --env-file=./.env --name matrix-chatgpt-bot matrix-chatgpt-bot
Note: Without -it flags in the command above you won't be able to stop the container using Ctrl-C
Note: In order to see the output of your console you need to run docker logs matrix-chatgpt-bot
If you prefer you can use a docker-compose file. Copy the content below and save it in a file named docker-compose.yml
. Either with a self-build image (run docker build . -t matrix-chatgpt-bot
from your local git repo location) or with the latest stable pre-built release from this repo (the recommended way).
The script will look for the .env
file in the same folder as the docker-compose.yml
. The key storage folder storage
will be created in the same folder as well. Adjust the locations to your needs.
version: '3.7'
services:
matrix-chatgpt-bot:
container_name: matrix-chatgpt-bot
image: ghcr.io/matrixgpt/matrix-chatgpt-bot:latest ## change to "matrix-chatgpt-bot" if you want to use your self-build image
volumes:
- ./storage:/storage
env_file:
- ./.env
Important: It is strongly recommended to run this package under Docker to not need to install various dependencies manually.
Nevertheless, you can also run it by using the package manager yarn (get it via apt install -y yarn
). You might also need to have a newer version of Node.js and other missing packages.
yarn
yarn build
yarn start
You only need to do this if you want to contribute code to this package.
- Run
yarn
- Run
yarn build
- By default "storage"-folder contains all your encryption keys. If you delete it, you will loose access to all your encrypted messages.
- You can use a Keyv storage backend for persistence if you prefer (advanced).
- The bot uses threads by default, to keep the context you should reply to this thread or the bot will think its a new conversation. "Threads" were previously experimental, you may need to activate them in your client's settings (e.g. in Element in the "lab"-section).
- There is support to set the context to work at either the:
- room level
- thread level
- both (threads fork the conversation from the main room)
Encryption works great with this package but can sometimes be a bit sensitive. Following steps can help to solve the "encryption" error
- Don't use a
MATRIX_ACCESS_TOKEN
extracted via Element-App, use the generated token from the bot based on yourMATRIX_BOT_USERNAME
&MATRIX_BOT_PASSWORD
set in theenv
file. It will be visible in the console at start up if theMATRIX_ACCESS_TOKEN
is not already set:
- Remove the
MATRIX_ACCESS_TOKEN
from theenv
file and make sureMATRIX_BOT_USERNAME
&MATRIX_BOT_PASSWORD
are set - Re-run the bot
- Copy the token from console output to your
env
file - Restart the bot again.
- If all fails, you can always reset your key storage. It's important to exercise all of the following steps, because any remaining data could lead to the next encryption error. Once everything is working, make sure to not touch the "storage" folder anymore:
- Stop the bot
- Delete the "storage" folder
- Delete all user data for the matrix bot account (e.g. use Synapse-Admin) or create a fresh bot user account (you can then skip step 4)
- Log into your bot account (e.g. via Element) and log out of all sessions
- Verify the correctness of your
env
file and then run the bot setup again (e.g. viadocker-compose up
if you use docker-compose).
- Set
MATRIX_ENCRYPTION=false
in your env-file and restart the bot. If it previously was running with encryption switched on, you need to create a new room with the bot as encryption can't be switched off once it was activated.
- So far, its not known to cause issues, you can safely ignore it.
Once the bot has started succesfully, it will output the following information to your console.
[INFO] [index] Starting bot...
[INFO] [MatrixClientLite] End-to-end encryption enabled
## this depends on your setup[INFO] [index] Bot started!
You most likely need to view the logs by running docker logs matrix-chatgpt-bot
Please report issues via Github. The chat room is for discussion.
Please use the search on Github and Matrix before asking for support.
Join #matrix-chatgpt-bot:matrix.org with any Matrix chat client or on the web!
If you've never set up a Matrix client before you can follow the prompts to get started.
GNU AGPLv3. See LICENSE