From 0ec1868b951b4632767f7065277def9011918abc Mon Sep 17 00:00:00 2001 From: bertybuttface <110790513+bertybuttface@users.noreply.github.com> Date: Mon, 2 Jan 2023 18:16:38 +0000 Subject: [PATCH 1/6] Add matrix-bot-chatgpt. Co-Authored-By: Slavi Pantaleev --- README.md | 1 + docs/configuring-playbook-bot-chatgpt.md | 69 ++++++++++++++++ group_vars/matrix_servers | 2 + playbooks/matrix.yml | 1 + .../matrix-bot-chatgpt/defaults/main.yml | 78 +++++++++++++++++++ .../custom/matrix-bot-chatgpt/tasks/main.yml | 20 +++++ .../tasks/setup_install.yml | 63 +++++++++++++++ .../tasks/setup_uninstall.yml | 25 ++++++ .../tasks/validate_config.yml | 12 +++ .../matrix-bot-chatgpt/templates/env.j2 | 25 ++++++ .../systemd/matrix-bot-chatgpt.service.j2 | 40 ++++++++++ 11 files changed, 336 insertions(+) create mode 100644 docs/configuring-playbook-bot-chatgpt.md create mode 100644 roles/custom/matrix-bot-chatgpt/defaults/main.yml create mode 100644 roles/custom/matrix-bot-chatgpt/tasks/main.yml create mode 100644 roles/custom/matrix-bot-chatgpt/tasks/setup_install.yml create mode 100644 roles/custom/matrix-bot-chatgpt/tasks/setup_uninstall.yml create mode 100644 roles/custom/matrix-bot-chatgpt/tasks/validate_config.yml create mode 100644 roles/custom/matrix-bot-chatgpt/templates/env.j2 create mode 100644 roles/custom/matrix-bot-chatgpt/templates/systemd/matrix-bot-chatgpt.service.j2 diff --git a/README.md b/README.md index 177c2a0d8..2a09ef418 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ Bots provide various additional functionality to your installation. | [Go-NEB](https://github.com/matrix-org/go-neb) | x | A multi functional bot written in Go | [Link](docs/configuring-playbook-bot-go-neb.md) | | [Mjolnir](https://github.com/matrix-org/mjolnir) | x | A moderation tool for Matrix | [Link](docs/configuring-playbook-bot-mjolnir.md) | | [Buscarron](https://gitlab.com/etke.cc/buscarron) | x | Web forms (HTTP POST) to matrix | [Link](docs/configuring-playbook-bot-buscarron.md) | +| [matrix-chatgpt-bot](https://github.com/matrixgpt/matrix-chatgpt-bot) | x | ChatGPT from matrix | [Link](docs/configuring-playbook-bot-chatgpt.md) | ### Administration diff --git a/docs/configuring-playbook-bot-chatgpt.md b/docs/configuring-playbook-bot-chatgpt.md new file mode 100644 index 000000000..49b3fddef --- /dev/null +++ b/docs/configuring-playbook-bot-chatgpt.md @@ -0,0 +1,69 @@ +# Setting up ChatGPT (optional) + +The playbook can install and configure [matrix-chatgpt-bot](https://github.com/matrixgpt/matrix-chatgpt-bot) for you. + +Talk to ChatGPT via your favourite Matrix client! + + +## 1. Register the bot account + +The playbook does not automatically create users for you. The bot requires an access token to be able to connect to your homeserver. + +You **need to register the bot user manually** before setting up the bot. + +Choose a strong password for the bot. You can generate a good password with a command like this: `pwgen -s 64 1`. + +You can use the playbook to [register a new user](registering-users.md): + +``` +ansible-playbook -i inventory/hosts setup.yml --extra-vars='username=bot.chatgpt password=PASSWORD_FOR_THE_BOT admin=no' --tags=register-user +``` + + +## 2. Get an access token + +Refer to the documentation on [how to obtain an access token](obtaining-access-tokens.md). + + +## 3. Adjusting the playbook configuration + +Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars.yml` file (adapt to your needs): + +```yaml +matrix_bot_chatgpt_enabled: true +# See instructions on +# https://www.npmjs.com/package/chatgpt +matrix_bot_chatgpt_openai_email: '' +matrix_bot_chatgpt_openai_password: '' +matrix_bot_chatgpt_openai_login_type: google +# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN +matrix_bot_chatgpt_matrix_bot_username: '@bot.chatgpt:{{ matrix_domain }}' +# Matrix access token (from bot user above) +# see: https://webapps.stackexchange.com/questions/131056/how-to-get-an-access-token-for-element-riot-matrix +matrix_bot_chatgpt_matrix_access_token: '' +matrix_bot_chatgpt_matrix_default_prefix: '!chatgpt ' +matrix_bot_chatgpt_matrix_default_prefix_reply: false +matrix_bot_chatgpt_matrix_whitelist: ':{{ matrix_domain }}' +``` + +You will need to get tokens for ChatGPT. + + +## 4. Installing + +After configuring the playbook, run the [installation](installing.md) command again: + +```sh +ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start +``` + +**Notes**: + +- if you change the bot password (`matrix_bot_chatgpt_matrix_password` in your `vars.yml` file) subsequently, the bot user's credentials on the homeserver won't be updated automatically. If you'd like to change the bot user's password, use a tool like [synapse-admin](configuring-playbook-synapse-admin.md) to change it, and then update `matrix_bot_chatgpt_matrix_password` to let the bot know its new password + + +## Usage + +To use the bot, invite the `@bot.chatgpt:DOMAIN` to the room you specified in a config, after that start speaking to it, use the prefix if you configured one or mention the bot. + +You can also refer to the upstream [documentation](https://github.com/matrixgpt/matrix-chatgpt-bot). diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 33c124014..6b8efb334 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -187,6 +187,8 @@ devture_systemd_service_manager_services_list_auto: | + ([{'name': 'matrix-bot-postmoogle.service', 'priority': 2200, 'groups': ['matrix', 'bots', 'postmoogle']}] if matrix_bot_postmoogle_enabled else []) + + ([{'name': 'matrix-bot-chatgpt.service', 'priority': 2200, 'groups': ['matrix', 'bots', 'chatgpt']}] if matrix_bot_chatgpt_enabled else []) + + ([{'name': 'matrix-appservice-discord.service', 'priority': 2000, 'groups': ['matrix', 'bridges', 'appservice-discord']}] if matrix_appservice_discord_enabled else []) + ([{'name': 'matrix-appservice-irc.service', 'priority': 2000, 'groups': ['matrix', 'bridges', 'appservice-irc']}] if matrix_appservice_irc_enabled else []) diff --git a/playbooks/matrix.yml b/playbooks/matrix.yml index 088ea6406..b0b83109c 100755 --- a/playbooks/matrix.yml +++ b/playbooks/matrix.yml @@ -78,6 +78,7 @@ - custom/matrix-bot-postmoogle - custom/matrix-bot-go-neb - custom/matrix-bot-mjolnir + - custom/matrix-bot-chatgpt - custom/matrix-cactus-comments - custom/matrix-synapse - custom/matrix-synapse-reverse-proxy-companion diff --git a/roles/custom/matrix-bot-chatgpt/defaults/main.yml b/roles/custom/matrix-bot-chatgpt/defaults/main.yml new file mode 100644 index 000000000..002ebabd5 --- /dev/null +++ b/roles/custom/matrix-bot-chatgpt/defaults/main.yml @@ -0,0 +1,78 @@ +--- +# chatgpt is a bot for chatting to openAI chatgpt matrix bot +# Project source code URL: https://github.com/matrixgpt/matrix-chatgpt-bot + +matrix_bot_chatgpt_enabled: true + +matrix_bot_chatgpt_container_image_self_build: false +matrix_bot_chatgpt_docker_repo: "https://github.com/matrixgpt/matrix-chatgpt-bot" +matrix_bot_chatgpt_docker_repo_version: "{{ 'latest' if matrix_bot_chatgpt_version == 'latest' else matrix_bot_chatgpt_version }}" +matrix_bot_chatgpt_docker_src_files_path: "{{ matrix_base_data_path }}/chatgpt/docker-src" + +matrix_bot_chatgpt_version: 1.1.1 +matrix_bot_chatgpt_docker_image: "{{ matrix_bot_chatgpt_docker_image_name_prefix }}matrixgpt/matrix-chatgpt-bot:{{ matrix_bot_chatgpt_version }}" +matrix_bot_chatgpt_docker_image_name_prefix: "{{ 'localhost/' if matrix_bot_chatgpt_container_image_self_build else 'ghcr.io/' }}" +matrix_bot_chatgpt_docker_image_force_pull: "{{ matrix_bot_chatgpt_docker_image.endswith(':latest') }}" + +matrix_bot_chatgpt_base_path: "{{ matrix_base_data_path }}/chatgpt" +matrix_bot_chatgpt_config_path: "{{ matrix_bot_chatgpt_base_path }}/config" +matrix_bot_chatgpt_data_path: "{{ matrix_bot_chatgpt_base_path }}/data" + +# A list of extra arguments to pass to the container +matrix_bot_chatgpt_container_extra_arguments: [] + +# List of systemd services that matrix-bot-chatgpt.service depends on +matrix_bot_chatgpt_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-bot-chatgpt.service wants +matrix_bot_chatgpt_systemd_wanted_services_list: [] + +# ChatGPT Settings +matrix_bot_chatgpt_openai_email: '' # OPENAI_EMAIL= +matrix_bot_chatgpt_openai_password: '' # OPENAI_PASSWORD= +matrix_bot_chatgpt_openai_login_type: 'google' # OPENAI_LOGIN_TYPE="google" + +# Matrix Static Settings (required, see notes) +# Defaults to "https://matrix.org" +matrix_bot_chatgpt_matrix_homeserver_url: "{{ matrix_homeserver_container_url }}" # MATRIX_HOMESERVER_URL= +# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN, needs to be set, created manually beforehand. +matrix_bot_chatgpt_matrix_bot_username: '@bot.chatgpt:{{ matrix_domain }}' # MATRIX_BOT_USERNAME= +# Set `MATRIX_BOT_PASSWORD` the bot will print an `MATRIX_ACCESS_TOKEN` to the terminal +# or https://webapps.stackexchange.com/questions/131056/how-to-get-an-access-token-for-element-riot-matrix +matrix_bot_chatgpt_matrix_access_token: '' # MATRIX_ACCESS_TOKEN= +# Once `MATRIX_BOT_ACCESS_TOKEN` is set this is no longer used. +matrix_bot_chatgpt_matrix_bot_password: '' # MATRIX_BOT_PASSWORD= + +# Matrix Configurable Settings Defaults (optional) +matrix_bot_chatgpt_matrix_default_prefix: "!chatgpt " # MATRIX_DEFAULT_PREFIX= Leave prefix blank to reply to all messages, trailing space matters +matrix_bot_chatgpt_matrix_default_prefix_reply: false # MATRIX_DEFAULT_PREFIX_REPLY= + +# Matrix Access Control (optional) +matrix_bot_chatgpt_matrix_blacklist: '' +matrix_bot_chatgpt_matrix_whitelist: ':{{ matrix_domain }}' + +# Matrix Feature Flags (optional) +matrix_bot_chatgpt_matrix_autojoin: true # MATRIX_AUTOJOIN=true +matrix_bot_chatgpt_matrix_encryption: true # MATRIX_ENCRYPTION=true +matrix_bot_chatgpt_matrix_threads: true # MATRIX_THREADS=true +matrix_bot_chatgpt_matrix_rich_text: true # MATRIX_RICH_TEXT=true + + +# A list of admins +# Example set of rules: +# matrix_bot_chatgpt_admins: +# - @someone:example.com +# - @another:example.com +# - @bot.*:example.com +# - @*:another.com +# matrix_bot_chatgpt_admins: "{{ [matrix_admin] if matrix_admin else [] }}" + +# Log level +# matrix_bot_chatgpt_loglevel: 'INFO' + +# Additional environment variables to pass to the chatgpt container +# +# Example: +# matrix_bot_chatgpt_environment_variables_extension: | +# chatgpt_TEXT_DONE=Done +matrix_bot_chatgpt_environment_variables_extension: '' diff --git a/roles/custom/matrix-bot-chatgpt/tasks/main.yml b/roles/custom/matrix-bot-chatgpt/tasks/main.yml new file mode 100644 index 000000000..c5487fb81 --- /dev/null +++ b/roles/custom/matrix-bot-chatgpt/tasks/main.yml @@ -0,0 +1,20 @@ +--- + +- block: + - when: matrix_bot_chatgpt_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml" + + - when: matrix_bot_chatgpt_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_install.yml" + tags: + - setup-all + - setup-bot-chatgpt + - install-all + - install-bot-chatgpt + +- block: + - when: not matrix_bot_chatgpt_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + tags: + - setup-all + - setup-bot-chatgpt diff --git a/roles/custom/matrix-bot-chatgpt/tasks/setup_install.yml b/roles/custom/matrix-bot-chatgpt/tasks/setup_install.yml new file mode 100644 index 000000000..5ae5ea953 --- /dev/null +++ b/roles/custom/matrix-bot-chatgpt/tasks/setup_install.yml @@ -0,0 +1,63 @@ +--- +- name: Ensure chatgpt paths exist + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_bot_chatgpt_config_path }}", when: true} + - {path: "{{ matrix_bot_chatgpt_data_path }}", when: true} + - {path: "{{ matrix_bot_chatgpt_docker_src_files_path }}", when: matrix_bot_chatgpt_container_image_self_build} + when: "item.when | bool" + +- name: Ensure chatgpt environment variables file created + ansible.builtin.template: + src: "{{ role_path }}/templates/env.j2" + dest: "{{ matrix_bot_chatgpt_config_path }}/env" + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + mode: 0640 + +- name: Ensure chatgpt image is pulled + community.docker.docker_image: + name: "{{ matrix_bot_chatgpt_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_bot_chatgpt_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" + force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_chatgpt_docker_image_force_pull }}" + when: "not matrix_bot_chatgpt_container_image_self_build | bool" + register: result + retries: "{{ devture_playbook_help_container_retries_count }}" + delay: "{{ devture_playbook_help_container_retries_delay }}" + until: result is not failed + +- name: Ensure chatgpt repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_bot_chatgpt_docker_repo }}" + version: "{{ matrix_bot_chatgpt_docker_repo_version }}" + dest: "{{ matrix_bot_chatgpt_docker_src_files_path }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_bot_chatgpt_git_pull_results + when: "matrix_bot_chatgpt_container_image_self_build | bool" + +- name: Ensure chatgpt image is built + community.docker.docker_image: + name: "{{ matrix_bot_chatgpt_docker_image }}" + source: build + force_source: "{{ matrix_bot_chatgpt_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" + force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}" + build: + dockerfile: Dockerfile + path: "{{ matrix_bot_chatgpt_docker_src_files_path }}" + pull: true + when: "matrix_bot_chatgpt_container_image_self_build | bool" + +- name: Ensure matrix-bot-chatgpt.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-bot-chatgpt.service.j2" + dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-chatgpt.service" + mode: 0644 + register: matrix_bot_chatgpt_systemd_service_result diff --git a/roles/custom/matrix-bot-chatgpt/tasks/setup_uninstall.yml b/roles/custom/matrix-bot-chatgpt/tasks/setup_uninstall.yml new file mode 100644 index 000000000..4a50d7337 --- /dev/null +++ b/roles/custom/matrix-bot-chatgpt/tasks/setup_uninstall.yml @@ -0,0 +1,25 @@ +--- + +- name: Check existence of matrix-chatgpt service + ansible.builtin.stat: + path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-chatgpt.service" + register: matrix_bot_chatgpt_service_stat + +- when: matrix_bot_chatgpt_service_stat.stat.exists | bool + block: + - name: Ensure matrix-chatgpt is stopped + ansible.builtin.service: + name: matrix-bot-chatgpt + state: stopped + enabled: false + daemon_reload: true + + - name: Ensure matrix-bot-chatgpt.service doesn't exist + ansible.builtin.file: + path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-chatgpt.service" + state: absent + + - name: Ensure Matrix chatgpt paths don't exist + ansible.builtin.file: + path: "{{ matrix_bot_chatgpt_base_path }}" + state: absent diff --git a/roles/custom/matrix-bot-chatgpt/tasks/validate_config.yml b/roles/custom/matrix-bot-chatgpt/tasks/validate_config.yml new file mode 100644 index 000000000..f68d0e5c2 --- /dev/null +++ b/roles/custom/matrix-bot-chatgpt/tasks/validate_config.yml @@ -0,0 +1,12 @@ +--- + +- name: Fail if required Chatgpt settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item.name }}`). + when: "item.when | bool and vars[item.name] == ''" + with_items: + - {'name': 'matrix_bot_chatgpt_openai_email', when: true} + - {'name': 'matrix_bot_chatgpt_openai_password', when: true} + - {'name': 'matrix_bot_chatgpt_openai_login_type', when: true} + - {'name': 'matrix_bot_chatgpt_matrix_bot_username', when: true} diff --git a/roles/custom/matrix-bot-chatgpt/templates/env.j2 b/roles/custom/matrix-bot-chatgpt/templates/env.j2 new file mode 100644 index 000000000..8837fe3ef --- /dev/null +++ b/roles/custom/matrix-bot-chatgpt/templates/env.j2 @@ -0,0 +1,25 @@ +MATRIX_HOMESERVER_URL={{ matrix_bot_chatgpt_matrix_homeserver_url }} +MATRIX_ACCESS_TOKEN={{ matrix_bot_chatgpt_matrix_access_token }} + +OPENAI_EMAIL={{ matrix_bot_chatgpt_openai_email }} +OPENAI_PASSWORD={{ matrix_bot_chatgpt_openai_password }} +OPENAI_LOGIN_TYPE={{ matrix_bot_chatgpt_openai_login_type }} + +# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN +MATRIX_BOT_USERNAME={{ matrix_bot_chatgpt_matrix_bot_username }} +MATRIX_BOT_PASSWORD={{ matrix_bot_chatgpt_matrix_bot_password }} + +MATRIX_DEFAULT_PREFIX={{ matrix_bot_chatgpt_matrix_default_prefix }} +MATRIX_DEFAULT_PREFIX_REPLY={{ matrix_bot_chatgpt_matrix_default_prefix_reply|lower }} + +MATRIX_BLACKLIST={{ matrix_bot_chatgpt_matrix_blacklist }} +MATRIX_WHITELIST={{ matrix_bot_chatgpt_matrix_whitelist }} + +MATRIX_AUTOJOIN={{ matrix_bot_chatgpt_matrix_autojoin|lower }} +MATRIX_ENCRYPTION={{ matrix_bot_chatgpt_matrix_encryption|lower }} +MATRIX_THREADS={{ matrix_bot_chatgpt_matrix_threads|lower }} +MATRIX_RICH_TEXT={{ matrix_bot_chatgpt_matrix_rich_text|lower }} + +DATA_PATH=/data/ + +{{ matrix_bot_chatgpt_environment_variables_extension }} diff --git a/roles/custom/matrix-bot-chatgpt/templates/systemd/matrix-bot-chatgpt.service.j2 b/roles/custom/matrix-bot-chatgpt/templates/systemd/matrix-bot-chatgpt.service.j2 new file mode 100644 index 000000000..4a528126a --- /dev/null +++ b/roles/custom/matrix-bot-chatgpt/templates/systemd/matrix-bot-chatgpt.service.j2 @@ -0,0 +1,40 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=Matrix chatgpt bot +{% for service in matrix_bot_chatgpt_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_bot_chatgpt_systemd_wanted_services_list %} +Wants={{ service }} +{% endfor %} +DefaultDependencies=no + +[Service] +Type=simple +Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" +ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} kill matrix-bot-chatgpt 2>/dev/null || true' +ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-chatgpt 2>/dev/null || true' + +ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-bot-chatgpt \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --read-only \ + --tmpfs /tmp \ + --network={{ matrix_docker_network }} \ + --env-file={{ matrix_bot_chatgpt_config_path }}/env \ + --mount type=bind,src={{ matrix_bot_chatgpt_data_path }},dst=/data \ + {% for arg in matrix_bot_chatgpt_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + {{ matrix_bot_chatgpt_docker_image }} + +ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} kill matrix-bot-chatgpt 2>/dev/null || true' +ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-bot-chatgpt 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-bot-chatgpt + +[Install] +WantedBy=multi-user.target From 0b8829339360342e584836c4f251f150771824fd Mon Sep 17 00:00:00 2001 From: bertybuttface <110790513+bertybuttface@users.noreply.github.com> Date: Tue, 10 Jan 2023 14:09:08 +0000 Subject: [PATCH 2/6] Bump ChatGPT version. --- roles/custom/matrix-bot-chatgpt/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/custom/matrix-bot-chatgpt/defaults/main.yml b/roles/custom/matrix-bot-chatgpt/defaults/main.yml index 002ebabd5..f85fc8f56 100644 --- a/roles/custom/matrix-bot-chatgpt/defaults/main.yml +++ b/roles/custom/matrix-bot-chatgpt/defaults/main.yml @@ -9,7 +9,7 @@ matrix_bot_chatgpt_docker_repo: "https://github.com/matrixgpt/matrix-chatgpt-bot matrix_bot_chatgpt_docker_repo_version: "{{ 'latest' if matrix_bot_chatgpt_version == 'latest' else matrix_bot_chatgpt_version }}" matrix_bot_chatgpt_docker_src_files_path: "{{ matrix_base_data_path }}/chatgpt/docker-src" -matrix_bot_chatgpt_version: 1.1.1 +matrix_bot_chatgpt_version: 1.2.1 matrix_bot_chatgpt_docker_image: "{{ matrix_bot_chatgpt_docker_image_name_prefix }}matrixgpt/matrix-chatgpt-bot:{{ matrix_bot_chatgpt_version }}" matrix_bot_chatgpt_docker_image_name_prefix: "{{ 'localhost/' if matrix_bot_chatgpt_container_image_self_build else 'ghcr.io/' }}" matrix_bot_chatgpt_docker_image_force_pull: "{{ matrix_bot_chatgpt_docker_image.endswith(':latest') }}" From 8d3ce50d1bb0d2d364ba32e0b7100579f98afff4 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Tue, 10 Jan 2023 17:20:33 +0200 Subject: [PATCH 3/6] Disable chatgpt from group_vars/matrix_servers by default --- group_vars/matrix_servers | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 6b8efb334..5e1f01237 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -1616,6 +1616,22 @@ matrix_bot_postmoogle_database_password: "{{ '%s' | format(matrix_homeserver_gen ###################################################################### +###################################################################### +# +# matrix-bot-chatgpt +# +###################################################################### + +# We don't enable bots by default. +matrix_bot_chatgpt_enabled: false + +###################################################################### +# +# /matrix-bot-chatgpt +# +###################################################################### + + ###################################################################### # # matrix-bot-go-neb From ddfab6042797311d8c87a2abda2c58ed95800f60 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Tue, 10 Jan 2023 17:20:50 +0200 Subject: [PATCH 4/6] Enable self-building for chatgpt for arm32 --- group_vars/matrix_servers | 2 ++ 1 file changed, 2 insertions(+) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 5e1f01237..78c45d0b8 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -1625,6 +1625,8 @@ matrix_bot_postmoogle_database_password: "{{ '%s' | format(matrix_homeserver_gen # We don't enable bots by default. matrix_bot_chatgpt_enabled: false +matrix_bot_chatgpt_container_image_self_build: "{{ matrix_architecture not in ['amd64', 'arm64'] }}" + ###################################################################### # # /matrix-bot-chatgpt From 9ecca2cbb9a3785046e5d79d560ab540ce0000a5 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Tue, 10 Jan 2023 17:22:54 +0200 Subject: [PATCH 5/6] Update documentation with more chatgpt mentions --- docs/configuring-playbook-bot-chatgpt.md | 2 +- docs/configuring-playbook.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/configuring-playbook-bot-chatgpt.md b/docs/configuring-playbook-bot-chatgpt.md index 49b3fddef..1856fb356 100644 --- a/docs/configuring-playbook-bot-chatgpt.md +++ b/docs/configuring-playbook-bot-chatgpt.md @@ -2,7 +2,7 @@ The playbook can install and configure [matrix-chatgpt-bot](https://github.com/matrixgpt/matrix-chatgpt-bot) for you. -Talk to ChatGPT via your favourite Matrix client! +Talk to [ChatGPT](https://openai.com/blog/chatgpt/) via your favourite Matrix client! ## 1. Register the bot account diff --git a/docs/configuring-playbook.md b/docs/configuring-playbook.md index fa00c858d..27ff1baeb 100644 --- a/docs/configuring-playbook.md +++ b/docs/configuring-playbook.md @@ -161,6 +161,8 @@ When you're done with all the configuration you'd like to do, continue with [Ins ### Bots +- [Setting up matrix-bot-chatgpt](configuring-playbook-bot-chatgpt.md) - talk to [ChatGPT](https://openai.com/blog/chatgpt/) via your favourite Matrix client (optional) + - [Setting up matrix-reminder-bot](configuring-playbook-bot-matrix-reminder-bot.md) - a bot to remind you about stuff (optional) - [Setting up matrix-registration-bot](configuring-playbook-bot-matrix-registration-bot.md) - a bot to create and manage registration tokens to invite users (optional) From a96a22c925051866a41cfbae4e4ca9d4452b7442 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Tue, 10 Jan 2023 17:26:59 +0200 Subject: [PATCH 6/6] chatgpt docs updates --- docs/configuring-playbook-bot-chatgpt.md | 16 ++++++---------- .../custom/matrix-bot-chatgpt/defaults/main.yml | 3 ++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/configuring-playbook-bot-chatgpt.md b/docs/configuring-playbook-bot-chatgpt.md index 1856fb356..eb0c75966 100644 --- a/docs/configuring-playbook-bot-chatgpt.md +++ b/docs/configuring-playbook-bot-chatgpt.md @@ -31,19 +31,19 @@ Add the following configuration to your `inventory/host_vars/matrix.DOMAIN/vars. ```yaml matrix_bot_chatgpt_enabled: true + # See instructions on # https://www.npmjs.com/package/chatgpt matrix_bot_chatgpt_openai_email: '' matrix_bot_chatgpt_openai_password: '' matrix_bot_chatgpt_openai_login_type: google -# With the @ and :DOMAIN, ie @SOMETHING:DOMAIN -matrix_bot_chatgpt_matrix_bot_username: '@bot.chatgpt:{{ matrix_domain }}' + +# This is the default username +# matrix_bot_chatgpt_matrix_bot_username_localpart: 'bot.chatgpt' + # Matrix access token (from bot user above) # see: https://webapps.stackexchange.com/questions/131056/how-to-get-an-access-token-for-element-riot-matrix matrix_bot_chatgpt_matrix_access_token: '' -matrix_bot_chatgpt_matrix_default_prefix: '!chatgpt ' -matrix_bot_chatgpt_matrix_default_prefix_reply: false -matrix_bot_chatgpt_matrix_whitelist: ':{{ matrix_domain }}' ``` You will need to get tokens for ChatGPT. @@ -54,13 +54,9 @@ You will need to get tokens for ChatGPT. After configuring the playbook, run the [installation](installing.md) command again: ```sh -ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start +ansible-playbook -i inventory/hosts setup.yml --tags=install-all,start ``` -**Notes**: - -- if you change the bot password (`matrix_bot_chatgpt_matrix_password` in your `vars.yml` file) subsequently, the bot user's credentials on the homeserver won't be updated automatically. If you'd like to change the bot user's password, use a tool like [synapse-admin](configuring-playbook-synapse-admin.md) to change it, and then update `matrix_bot_chatgpt_matrix_password` to let the bot know its new password - ## Usage diff --git a/roles/custom/matrix-bot-chatgpt/defaults/main.yml b/roles/custom/matrix-bot-chatgpt/defaults/main.yml index f85fc8f56..361aa3511 100644 --- a/roles/custom/matrix-bot-chatgpt/defaults/main.yml +++ b/roles/custom/matrix-bot-chatgpt/defaults/main.yml @@ -36,7 +36,8 @@ matrix_bot_chatgpt_openai_login_type: 'google' # OPENAI_LOGIN_TYPE="google" # Defaults to "https://matrix.org" matrix_bot_chatgpt_matrix_homeserver_url: "{{ matrix_homeserver_container_url }}" # MATRIX_HOMESERVER_URL= # With the @ and :DOMAIN, ie @SOMETHING:DOMAIN, needs to be set, created manually beforehand. -matrix_bot_chatgpt_matrix_bot_username: '@bot.chatgpt:{{ matrix_domain }}' # MATRIX_BOT_USERNAME= +matrix_bot_chatgpt_matrix_bot_username_localpart: 'bot.chatgpt' +matrix_bot_chatgpt_matrix_bot_username: "@{{ matrix_bot_chatgpt_matrix_bot_username_localpart }}:{{ matrix_domain }}" # MATRIX_BOT_USERNAME= # Set `MATRIX_BOT_PASSWORD` the bot will print an `MATRIX_ACCESS_TOKEN` to the terminal # or https://webapps.stackexchange.com/questions/131056/how-to-get-an-access-token-for-element-riot-matrix matrix_bot_chatgpt_matrix_access_token: '' # MATRIX_ACCESS_TOKEN=