Based on docs/obtaining-access-tokens.md Signed-off-by: Suguru Hirahara <acioustick@noreply.codeberg.org>
4.3 KiB
Setting up matrix-bot-chatgpt (optional, unmaintained)
Note: matrix-chatgpt-bot is now an archived (unmaintained) project. Talking to ChatGPT (and many other LLM providers) can happen via the much more featureful baibot, which can be installed using this playbook. Consider using that bot instead of this one.
The playbook can install and configure matrix-chatgpt-bot for you.
Talk to ChatGPT via your favourite Matrix client!
Prerequisites
Obtain an OpenAI API key
To use the bot, you'd need to obtain an API key from https://platform.openai.com/account/api-keys.
Register the bot account
The playbook does not automatically create users for you. You need to register the bot user manually before setting up the bot.
Generate a strong password for the bot. You can create one with a command like pwgen -s 64 1
.
You can use the playbook to register a new user:
ansible-playbook -i inventory/hosts setup.yml --extra-vars='username=bot.chatgpt password=PASSWORD_FOR_THE_BOT admin=no' --tags=register-user
Obtain an access token and create encryption keys
The bot requires an access token to be able to connect to your homeserver. Refer to the documentation on how to obtain an access token.
⚠️ Warning: Access tokens are sensitive information. Do not include them in any bug reports, messages, or logs. Do not share the access token with anyone.
To make sure the bot can read encrypted messages, it will need an encryption key, just like any other new user. While obtaining the access token, follow the prompts to setup a backup key. More information can be found in the Element documentation.
Adjusting the playbook configuration
To enable the bot, add the following configuration to your inventory/host_vars/matrix.example.com/vars.yml
file. Make sure to replace API_KEY_HERE
with the API key retrieved here and ACCESS_TOKEN_HERE
with the access token created here, respectively.
matrix_bot_chatgpt_enabled: true
matrix_bot_chatgpt_openai_api_key: 'API_KEY_HERE'
# Uncomment and adjust this part if you'd like to use a username different than the default
# matrix_bot_chatgpt_matrix_bot_username_localpart: 'bot.chatgpt'
matrix_bot_chatgpt_matrix_access_token: 'ACCESS_TOKEN_HERE'
# Configuring the system promt used, needed if the bot is used for special tasks.
# More information: https://github.com/mustvlad/ChatGPT-System-Prompts
matrix_bot_chatgpt_matrix_bot_prompt_prefix: 'Instructions:\nYou are ChatGPT, a large language model trained by OpenAI.'
Installing
After configuring the playbook, run it with playbook tags as below:
ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,ensure-matrix-users-created,start
Notes:
-
The
ensure-matrix-users-created
playbook tag makes the playbook automatically create the bot's user account. -
The shortcut commands with the
just
program are also available:just install-all
orjust setup-all
just install-all
is useful for maintaining your setup quickly (2x-5x faster thanjust setup-all
) when its components remain unchanged. If you adjust yourvars.yml
to remove other components, you'd need to runjust setup-all
, or these components will still remain installed.
Usage
To use the bot, invite it to the room you specified on your vars.yml
file (/invite @bot.chatgpt:example.com
where example.com
is your base domain, not the matrix.
domain).
After the bot joins the room, you can send a message to it. When you do so, use the prefix if you configured it or mention the bot.
You can also refer to the upstream documentation.