From 6f2c6734e6e283d825081761f7fdb8e7a8afc179 Mon Sep 17 00:00:00 2001 From: bertybuttface <110790513+bertybuttface@users.noreply.github.com> Date: Fri, 27 Jan 2023 18:43:53 +0000 Subject: [PATCH] Update README --- .env.example | 39 ++++++++++++++++ README.md | 124 ++++++++++++++++++++++----------------------------- 2 files changed, 92 insertions(+), 71 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..645f4d7 --- /dev/null +++ b/.env.example @@ -0,0 +1,39 @@ +# ChatGPT Settings (required) +OPENAI_EMAIL= +OPENAI_PASSWORD= +# What type of Login it is, possibility's are google, openai, microsoft +OPENAI_LOGIN_TYPE=google +# Set the next line to true if you are using a ChatGPT pro account. +OPENAI_PRO=false + +# Set the ChatGPT conversation context to 'thread', 'room' or 'both'. +CHATGPT_CONTEXT=thread + +# Matrix Static Settings (required, see notes) +# Defaults to "https://matrix.org" +MATRIX_HOMESERVER_URL= +# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN - Not used if `MATRIX_ACCESS_TOKEN` is set. +MATRIX_BOT_USERNAME= +# Set `MATRIX_BOT_PASSWORD` the bot will print an `MATRIX_ACCESS_TOKEN` to the terminal +MATRIX_ACCESS_TOKEN= +# Not used if `MATRIX_ACCESS_TOKEN` is set. +MATRIX_BOT_PASSWORD= + +# Matrix Configurable Settings Defaults (optional) +# Leave prefix blank to reply to all messages +MATRIX_DEFAULT_PREFIX=!chatgpt +MATRIX_DEFAULT_PREFIX_REPLY=false + +# Matrix Access Control (optional) +# Can be set to user:homeserver or a wildcard like :anotherhomeserver.example +MATRIX_BLACKLIST= +# `MATRIX_WHITELIST` is overriden by `MATRIX_BLACKLIST` if they contain same entry +MATRIX_WHITELIST= + +# Matrix Feature Flags (optional) +MATRIX_AUTOJOIN=true +MATRIX_ENCRYPTION=true +# If you turn threads off you will have problems if you don't set CHATGPT_CONTEXT=room +MATRIX_THREADS=true +MATRIX_PREFIX_DM=false +MATRIX_RICH_TEXT=true \ No newline at end of file diff --git a/README.md b/README.md index e3ac09c..c212980 100644 --- a/README.md +++ b/README.md @@ -5,91 +5,52 @@ Talk to ChatGPT via your favourite Matrix client! ![Screenshot of Element iOS app showing conversation with bot](img/matrix-chatgpt.png) -This is an unofficial Matrix bot that uses https://github.com/transitive-bullshit/chatgpt-api to access the unofficial ChatGPT API. - -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 `OPENAI_LOGIN_TYPE` to `google`. You should also note that if your Google account uses 2FA it will not work but there is a workaround detailed [here](https://github.com/transitive-bullshit/chatgpt-api/issues/169#issuecomment-1362206780) - -To get an access token you can provide MATRIX_USERNAME and MATRIX_PASSWORD whilst leaving MATRIX_ACCESS_TOKEN blank. This will print a token to the screen. You can then add this token to the MATRIX_ACCESS_TOKEN field. +A Matrix bot that uses [transitive-bullshit/chatgpt-api](https://github.com/transitive-bullshit/chatgpt-api) to access the unofficial ChatGPT API. # Usage -- Create an (encrypted if enabled) room -- Add the bot -- Start chatting away! +1. Create a room +2. Add the bot +3. Start chatting away! # Features - Shows typing indicator as ChatGPT is thinking! - Supports encryption +- Stores context for ChatGPT conversations + +# Configure + +## Bot -# 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`: ``` -# ChatGPT Settings (required) -OPENAI_EMAIL= -OPENAI_PASSWORD= -# What type of Login it is, possibility's are google, openai, microsoft -OPENAI_LOGIN_TYPE=google -# Set the next line to true if you are using a ChatGPT pro account. -OPENAI_PRO=false - -# Set the ChatGPT conversation context to 'thread', 'room' or 'both'. -CHATGPT_CONTEXT=thread - -# Matrix Static Settings (required, see notes) -# Defaults to "https://matrix.org" -MATRIX_HOMESERVER_URL= -# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN - Not used if `MATRIX_ACCESS_TOKEN` is set. -MATRIX_BOT_USERNAME= -# Set `MATRIX_BOT_PASSWORD` the bot will print an `MATRIX_ACCESS_TOKEN` to the terminal -MATRIX_ACCESS_TOKEN= -# Not used if `MATRIX_ACCESS_TOKEN` is set. -MATRIX_BOT_PASSWORD= - -# Matrix Configurable Settings Defaults (optional) -# Leave prefix blank to reply to all messages -MATRIX_DEFAULT_PREFIX=!chatgpt -MATRIX_DEFAULT_PREFIX_REPLY=false - -# Matrix Access Control (optional) -# Can be set to user:homeserver or a wildcard like :anotherhomeserver.example -MATRIX_BLACKLIST= -# `MATRIX_WHITELIST` is overriden by `MATRIX_BLACKLIST` if they contain same entry -MATRIX_WHITELIST= - -# Matrix Feature Flags (optional) -MATRIX_AUTOJOIN=true -MATRIX_ENCRYPTION=true -# If you turn threads off you will have problems if you don't set CHATGPT_CONTEXT=room -MATRIX_THREADS=true -MATRIX_PREFIX_DM=false -MATRIX_RICH_TEXT=true +cp .env.example .env ``` -# Discussion +You must adjust the settings in the `.env` file according to your needs. See below for help. -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. +## Matrix +You need a Matrix account on Matrix.org (or any other server). -# Local development setup -- Run `yarn` -- Run `yarn build` +The bot outputs MATRIX_ACCESS_TOKEN to the console if it is not already set but MATRIX_BOT_USERNAME & MATRIX_BOT_PASSWORD are. -## Running in "prod" -- `yarn` -- `yarn build` -- `yarn start` +You must set MATRIX_ACCESS_TOKEN to use this token. Do not use it with any other client. -## Running with Docker +You no longer need to use the MATRIX_BOT_PASSWORD field but you can leave it set if you want. + +## OpenAI / ChatGPT + +You must read the [authentication instructions](https://www.npmjs.com/package/chatgpt#usage) for chatgpt-api if you get stuck. + +Using the same account at [chat.openai.com](https://chat.openai.com) may refresh tokens invalidating the bot's session. + +Ensure your OpenAI account uses Google and set `OPENAI_LOGIN_TYPE` to `google`. + +**If the Google account uses 2FA it will fail** but there is [a workaround](https://github.com/transitive-bullshit/chatgpt-api/issues/169#issuecomment-1362206780) + +# Run + +## with Docker + +This is the recommended way to run this project. ``` docker build . -t matrix-chatgpt-bot @@ -98,5 +59,26 @@ docker run -it -v storage:/storage --env-file=./.env --name matrix-chatgpt-bot m Note: Without -it flags in the command above you won't be able to stop the container using Ctrl-C +## without Docker + +It is strongly recommended you run this package under Docker. + +- `yarn` +- `yarn build` +- `yarn start` + +## in Development + +You only need to do this if you want to contribute code to this package. + +- Run `yarn` +- Run `yarn build` + +# Discussion + +Join [#matrix-chatgpt-bot:matrix.org](https://matrix.to/#/#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. + # License GNU AGPLv3. See LICENSE