matrix-chatgpt-bot/README.md

97 lines
3.7 KiB
Markdown
Raw Normal View History

2022-12-09 04:41:17 -05:00
Matrix ChatGPT Bot
==================
Talk to ChatGPT via your favourite Matrix client!
2022-12-09 05:09:42 -05:00
![Screenshot of Element iOS app showing conversation with bot](img/matrix-chatgpt.png)
2022-12-09 05:27:05 -05:00
This is an unofficial Matrix bot that uses https://github.com/transitive-bullshit/chatgpt-api to access the unofficial ChatGPT API.
2022-12-09 04:41:17 -05:00
It is worth reading the [authentication instructions](https://www.npmjs.com/package/chatgpt#usage) for the unofficial ChatGPT API.
Your user-agent and IP address must match from the real browser window you're logged in with to the one you're using for ChatGPTAPI. This means that you currently can't log in with your laptop and then run the bot on a server or proxy somewhere.
Cloudflare will still sometimes ask you to complete a CAPTCHA, so you may need to keep an eye on it and manually resolve the CAPTCHA.
You should not be using this ChatGPT account while the bot is using it, because that browser window may refresh one of your tokens and invalidate the bot's session.
If your OpenAI account uses Google Auth, you shouldn't encounter any of the more complicated Recaptchas — and can avoid using paid third-party CAPTCHA solving providers. To use Google auth, make sure your OpenAI account is using Google and then set IS_GOOGLE_LOGIN to true.
2022-12-29 06:11:52 -05:00
If you want to get an access token without exposing your password to this bot you can follow [how-to-get-an-access-token-for-element-riot-matrix](https://webapps.stackexchange.com/questions/131056/how-to-get-an-access-token-for-element-riot-matrix).
2022-12-09 04:41:17 -05:00
# Usage
2022-12-28 21:38:29 -05:00
- Create an (encrypted if enabled) room
2022-12-09 04:41:17 -05:00
- Add the bot
- Start chatting away!
2022-12-09 05:09:14 -05:00
# Features
- Shows typing indicator as ChatGPT is thinking!
2022-12-29 06:11:52 -05:00
- Supports encryption
2022-12-09 05:09:14 -05:00
2022-12-09 04:41:17 -05:00
# Setting up the account
- Create a new Matrix account on Matrix.org (or your favourite server)
- Go to the settings and get the access token
- Add the details to your environment vars. One way of doing this is adding this to a file called `.env`:
```
2022-12-29 06:11:52 -05:00
# ChatGPT Settings (required)
OPENAI_EMAIL=
OPENAI_PASSWORD=
# What type of Login it is, possibility's are google, openai, microsoft
2023-01-06 18:59:52 -05:00
OPENAI_LOGIN_TYPE=google
2022-12-09 04:41:17 -05:00
2022-12-29 06:11:52 -05:00
# Matrix Static Settings (required, see notes)
# Defaults to "https://matrix.org"
MATRIX_HOMESERVER_URL=
2023-01-06 19:32:15 -05:00
# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN - Not used if `MATRIX_ACCESS_TOKEN` is set.
2022-12-09 04:41:17 -05:00
MATRIX_BOT_USERNAME=
2022-12-29 06:11:52 -05:00
# Set `MATRIX_BOT_PASSWORD` the bot will print an `MATRIX_ACCESS_TOKEN` to the terminal
MATRIX_ACCESS_TOKEN=
2023-01-06 19:32:15 -05:00
# Not used if `MATRIX_ACCESS_TOKEN` is set.
2022-12-09 04:41:17 -05:00
MATRIX_BOT_PASSWORD=
2022-12-28 21:38:29 -05:00
2022-12-29 06:11:52 -05:00
# Matrix Configurable Settings Defaults (optional)
# Leave prefix blank to reply to all messages
MATRIX_DEFAULT_PREFIX=!chatgpt
2022-12-29 06:11:52 -05:00
MATRIX_DEFAULT_PREFIX_REPLY=false
2022-12-28 18:16:21 -05:00
# Matrix Access Control (optional)
# Can be set to user:homeserver or a wildcard like :anotherhomeserver.example
MATRIX_BLACKLIST=
2023-01-07 19:17:58 -05:00
# `MATRIX_WHITELIST` is overriden by `MATRIX_BLACKLIST` if they contain same entry
MATRIX_WHITELIST=
2022-12-29 06:11:52 -05:00
# Matrix Feature Flags (optional)
MATRIX_AUTOJOIN=true
MATRIX_ENCRYPTION=true
MATRIX_THREADS=true
2023-01-08 16:02:47 -05:00
MATRIX_PREFIX_DM=false
MATRIX_RICH_TEXT=true
2022-12-09 04:41:17 -05:00
```
# Discussion
Come and join [#matrix-chatgpt-bot:matrix.org](https://matrix.to/#/#matrix-chatgpt-bot:matrix.org)
with your favourite Matrix chat client! If you've never set up a Matrix client before I'd
recomend following the prompts at https://element.io/get-started to download and sign into Element.
2022-12-09 04:41:17 -05:00
# Local development setup
- Run `yarn`
- Run `yarn build`
## Running in "prod"
- `yarn`
- `yarn build`
- `yarn start`
2022-12-22 10:19:17 -05:00
## Running with Docker
```
docker build . -t matrix-chatgpt-bot
docker run -it -v storage:/storage --env-file=./.env --name matrix-chatgpt-bot matrix-chatgpt-bot
2022-12-22 10:19:17 -05:00
```
Note: Without -it flags in the command above you won't be able to stop the container using Ctrl-C
2022-12-09 04:41:17 -05:00
# License
GNU AGPLv3. See LICENSE