From 1f730be7f31ae1f92196e4aec80cb435ff71f353 Mon Sep 17 00:00:00 2001 From: Jmackles <124995231+Jmackles@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:34:04 -0500 Subject: [PATCH 1/5] Update INSTALLATION.md Clarified Digital Ocean install instruction commands Signed-off-by: Jmackles <124995231+Jmackles@users.noreply.github.com> --- detailed_guides/INSTALLATION.md | 82 ++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/detailed_guides/INSTALLATION.md b/detailed_guides/INSTALLATION.md index 75f1e63..179bd09 100644 --- a/detailed_guides/INSTALLATION.md +++ b/detailed_guides/INSTALLATION.md @@ -80,54 +80,74 @@ To connect with ssh, run the following command in terminal: It will then prompt you for your password, which you should enter, and then you will be logged in. -After login, we need to install the various dependencies that the bot needs. To do this, we will run the following commands: +# After login, we need to install the various dependencies that the bot needs. To do this, we will run the following commands: ```shell -git clone https://github.com/Kav-K/GPT3Discord.git -cd GPT3Discord/ -# Install system packages (python) -sudo apt-get update -sudo apt install software-properties-common -sudo add-apt-repository ppa:deadsnakes/ppa -sudo apt install python3.9 -sudo apt install python3.9-distutils # If this doesn't work, try sudo apt install python3-distutils +git clone https://github.com/Kav-K/GPT3Discord.git``` + +```cd GPT3Discord/``` + +# Install system packages (python) +```sudo apt-get updat``` + +```sudo apt install software-properties-common``` + +```sudo add-apt-repository ppa:deadsnakes/ppa``` + +```sudo apt install python3.9``` + +```sudo apt install python3.9-distutils``` +# If this doesn't work, try sudo apt install python3-distutils + + # Install Pip for python3.9 -curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py -python3.9 get-pip.py +```curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py``` + +```python3.9 get-pip.py``` + # Install project dependencies -python3.9 -m pip install --ignore-installed PyYAML -python3.9 -m pip install torch==1.9.1+cpu torchvision==0.10.1+cpu -f https://download.pytorch.org/whl/torch_stable.html -python3.9 -m pip install -r requirements.txt -python3.9 -m pip install . + +```python3.9 -m pip install --ignore-installed PyYAML``` + +```python3.9 -m pip install torch==1.9.1+cpu torchvision==0.10.1+cpu -f https://download.pytorch.org/whl/torch_stable.html``` + +```python3.9 -m pip install -r requirements.txt``` + +```python3.9 -m pip install .``` + # Copy the sample.env file into a regular .env file. `DEBUG_GUILD` and the ID for `ALLOWED_GUILDS` can be found by right-clicking your server and choosing "Copy ID". Similarly, `DEBUG_CHANNEL` can be found by right-clicking your debug channel. -cp sample.env .env +```cp sample.env .env``` + # The command below is used to edit the .env file and to put in your API keys. You can right click within the # editor after running this command to paste. When you are done editing, press CTRL + X, and then type Y, to save. -nano .env +```nano .env``` + # Run the bot using [screen](https://www.gnu.org/software/screen/manual/screen.html) to keep it running after you disconnect from your SSH session: -screen gpt3discord +```screen gpt3discord``` + # Hit `Ctrl+a` then `d` to detach from the running bot. + # The bot's screen session can be reattached: -screen -r -``` +```screen -r``` + +#If the last few commands don't allow the bot to run `screen gpt3discord`, you can attempt to run the bot another way: -If the last few commands don't allow the bot to run `screen gpt3discord`, you can attempt to run the bot another way: -``` # First, navigate to the folder where the project files are -screen -dmS GPTBot bash -c 'python3.9 gpt3discord.py' +```screen -dmS GPTBot bash -c``` + +```python3.9 gpt3discord.py``` # Reattach to screen session -screen -x # will reattach if this is the only screen session, if there are multiple, it will show IDs +```screen -x``` +# will reattach if this is the only screen session, if there are multiple, it will show IDs # If there are multiple IDs returned by screen -x: -screen -d -r {ID} # replace {ID} with the ID of the screen session you want to reattach to -``` +```screen -d -r {ID}``` +# replace {ID} with the ID of the screen session you want to reattach to -As a last resort, you can try to run the bot using python in a basic way, with simply -``` -cd GPT3Discord +#As a last resort, you can try to run the bot using python in a basic way, with simply +```cd GPT3Discord``` -python3.9 gpt3discord.py -``` +```python3.9 gpt3discord.py ``` ### Docker and Docker Compose : From 1a487ae72d0f2202db2bb34d20865b930a3ff018 Mon Sep 17 00:00:00 2001 From: Kaveen Kumarasinghe Date: Thu, 2 Mar 2023 19:29:58 -0500 Subject: [PATCH 2/5] move settings/mod db into shared --- cogs/moderations_service_cog.py | 2 +- cogs/text_service_cog.py | 4 ++-- gpt3discord.py | 2 +- services/environment_service.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cogs/moderations_service_cog.py b/cogs/moderations_service_cog.py index 9cae7ff..968e16e 100644 --- a/cogs/moderations_service_cog.py +++ b/cogs/moderations_service_cog.py @@ -9,7 +9,7 @@ from services.moderations_service import Moderation, ThresholdSet MOD_DB = None try: print("Attempting to retrieve the General and Moderations DB") - MOD_DB = SqliteDict("main_db.sqlite", tablename="moderations", autocommit=True) + MOD_DB = SqliteDict(EnvService.find_shared_file("main_db.sqlite"), tablename="moderations", autocommit=True) except Exception as e: print("Failed to retrieve the General and Moderations DB") raise e diff --git a/cogs/text_service_cog.py b/cogs/text_service_cog.py index 9c37b72..e12b038 100644 --- a/cogs/text_service_cog.py +++ b/cogs/text_service_cog.py @@ -49,8 +49,8 @@ MOD_DB = None GENERAL_DB = None try: print("Attempting to retrieve the General and Moderations DB") - MOD_DB = SqliteDict("main_db.sqlite", tablename="moderations", autocommit=True) - GENERAL_DB = SqliteDict("main_db.sqlite", tablename="general", autocommit=True) + MOD_DB = SqliteDict(EnvService.find_shared_file("main_db.sqlite"), tablename="moderations", autocommit=True) + GENERAL_DB = SqliteDict(EnvService.find_shared_file("main_db.sqlite"), tablename="general", autocommit=True) print("Retrieved the General and Moderations DB") except Exception as e: print("Failed to retrieve the General and Moderations DB. The bot is terminating.") diff --git a/gpt3discord.py b/gpt3discord.py index a6881aa..adb608f 100644 --- a/gpt3discord.py +++ b/gpt3discord.py @@ -32,7 +32,7 @@ from services.environment_service import EnvService from models.openai_model import Model -__version__ = "10.9.7" +__version__ = "10.9.8" PID_FILE = Path("bot.pid") diff --git a/services/environment_service.py b/services/environment_service.py index 4bbd652..6a1ee35 100644 --- a/services/environment_service.py +++ b/services/environment_service.py @@ -347,7 +347,7 @@ class EnvService: print( "No user key database path was provided. Defaulting to user_key_db.sqlite" ) - user_key_db_path = "user_key_db.sqlite" + user_key_db_path = EnvService.find_shared_file("user_key_db.sqlite") else: # append "user_key_db.sqlite" to USER_KEY_DB_PATH if it doesn't already end with .sqlite if not user_key_db_path.match("*.sqlite"): From 33e06d2794337459cd691a0530b9b12c7931fcf0 Mon Sep 17 00:00:00 2001 From: Kaveen Kumarasinghe Date: Thu, 2 Mar 2023 19:54:40 -0500 Subject: [PATCH 3/5] update installation --- detailed_guides/INSTALLATION.md | 102 ++++++++++++++++---------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/detailed_guides/INSTALLATION.md b/detailed_guides/INSTALLATION.md index 179bd09..c20343f 100644 --- a/detailed_guides/INSTALLATION.md +++ b/detailed_guides/INSTALLATION.md @@ -80,74 +80,74 @@ To connect with ssh, run the following command in terminal: It will then prompt you for your password, which you should enter, and then you will be logged in. -# After login, we need to install the various dependencies that the bot needs. To do this, we will run the following commands: -```shell -git clone https://github.com/Kav-K/GPT3Discord.git``` - -```cd GPT3Discord/``` - -# Install system packages (python) -```sudo apt-get updat``` - -```sudo apt install software-properties-common``` - -```sudo add-apt-repository ppa:deadsnakes/ppa``` - -```sudo apt install python3.9``` - -```sudo apt install python3.9-distutils``` -# If this doesn't work, try sudo apt install python3-distutils - +## After login, we need to install the various dependencies that the bot needs. To do this, we will run the following commands: -# Install Pip for python3.9 -```curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py``` - -```python3.9 get-pip.py``` - -# Install project dependencies - -```python3.9 -m pip install --ignore-installed PyYAML``` +#### Clone the project files +```shell +git clone https://github.com/Kav-K/GPT3Discord.git +cd GPT3Discord/ +```` -```python3.9 -m pip install torch==1.9.1+cpu torchvision==0.10.1+cpu -f https://download.pytorch.org/whl/torch_stable.html``` +#### Install system packages (python) +```shell +sudo apt-get update +sudo apt install software-properties-common +sudo add-apt-repository ppa:deadsnakes/ppa +sudo apt install python3.9 +sudo apt install python3.9-distutils # If this doesn't work, try sudo apt install python3-distutils +``` -```python3.9 -m pip install -r requirements.txt``` +#### Install Pip for python3.9 +```shell +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py +python3.9 get-pip.py +``` -```python3.9 -m pip install .``` +#### Install project dependencies +``` +python3.9 -m pip install --ignore-installed PyYAML +python3.9 -m pip install torch==1.9.1+cpu torchvision==0.10.1+cpu -f https://download.pytorch.org/whl/torch_stable.html +python3.9 -m pip install -r requirements.txt +python3.9 -m pip install . +``` -# Copy the sample.env file into a regular .env file. `DEBUG_GUILD` and the ID for `ALLOWED_GUILDS` can be found by right-clicking your server and choosing "Copy ID". Similarly, `DEBUG_CHANNEL` can be found by right-clicking your debug channel. -```cp sample.env .env``` +#### Copy the sample.env file into a regular .env file. `DEBUG_GUILD` and the ID for `ALLOWED_GUILDS` can be found by right-clicking your server and choosing "Copy ID". Similarly, `DEBUG_CHANNEL` can be found by right-clicking your debug channel. +```shell +cp sample.env .env +``` -# The command below is used to edit the .env file and to put in your API keys. You can right click within the -# editor after running this command to paste. When you are done editing, press CTRL + X, and then type Y, to save. -```nano .env``` +#### The command below is used to edit the .env file and to put in your API keys. You can right click within the editor after running this command to paste. When you are done editing, press CTRL + X, and then type Y, to save. +```shell +nano .env +``` -# Run the bot using [screen](https://www.gnu.org/software/screen/manual/screen.html) to keep it running after you disconnect from your SSH session: -```screen gpt3discord``` +#### Run the bot using [screen](https://www.gnu.org/software/screen/manual/screen.html) to keep it running after you disconnect from your SSH session: +```shell +screen gpt3discord +``` -# Hit `Ctrl+a` then `d` to detach from the running bot. +#### Hit `Ctrl+a` then `d` to detach from the running bot. The bot's screen session can be reattached: `screen -r` -# The bot's screen session can be reattached: -```screen -r``` - -#If the last few commands don't allow the bot to run `screen gpt3discord`, you can attempt to run the bot another way: -# First, navigate to the folder where the project files are -```screen -dmS GPTBot bash -c``` +If the last few commands don't allow the bot to run `screen gpt3discord`, you can attempt to run the bot another way: -```python3.9 gpt3discord.py``` +``` shell +# First, navigate to the folder where the project files are +screen -dmS GPTBot bash -c 'python3.9 gpt3discord.py' # Reattach to screen session -```screen -x``` -# will reattach if this is the only screen session, if there are multiple, it will show IDs +screen -x # will reattach if this is the only screen session, if there are multiple, it will show IDs # If there are multiple IDs returned by screen -x: -```screen -d -r {ID}``` -# replace {ID} with the ID of the screen session you want to reattach to +screen -d -r {ID} # replace {ID} with the ID of the screen session you want to reattach to +``` -#As a last resort, you can try to run the bot using python in a basic way, with simply -```cd GPT3Discord``` +As a last resort, you can try to run the bot using python in a basic way, with simply +```shell +cd GPT3Discord -```python3.9 gpt3discord.py ``` +python3.9 gpt3discord.py +``` ### Docker and Docker Compose : From f999a7d9e97aed182776d19e9f7b6d6437a2114d Mon Sep 17 00:00:00 2001 From: Kaveen Kumarasinghe Date: Thu, 2 Mar 2023 23:11:26 -0500 Subject: [PATCH 4/5] Update gpt3discord.py Signed-off-by: Kaveen Kumarasinghe --- gpt3discord.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpt3discord.py b/gpt3discord.py index adb608f..ddac49e 100644 --- a/gpt3discord.py +++ b/gpt3discord.py @@ -32,7 +32,7 @@ from services.environment_service import EnvService from models.openai_model import Model -__version__ = "10.9.8" +__version__ = "10.9.9" PID_FILE = Path("bot.pid") From 3bf663778b2a56c614818069043354d4b6d5f156 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 3 Mar 2023 04:11:52 +0000 Subject: [PATCH 5/5] Format Python code with psf/black push --- cogs/moderations_service_cog.py | 6 +++++- cogs/text_service_cog.py | 12 ++++++++++-- models/index_model.py | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cogs/moderations_service_cog.py b/cogs/moderations_service_cog.py index 968e16e..743e52e 100644 --- a/cogs/moderations_service_cog.py +++ b/cogs/moderations_service_cog.py @@ -9,7 +9,11 @@ from services.moderations_service import Moderation, ThresholdSet MOD_DB = None try: print("Attempting to retrieve the General and Moderations DB") - MOD_DB = SqliteDict(EnvService.find_shared_file("main_db.sqlite"), tablename="moderations", autocommit=True) + MOD_DB = SqliteDict( + EnvService.find_shared_file("main_db.sqlite"), + tablename="moderations", + autocommit=True, + ) except Exception as e: print("Failed to retrieve the General and Moderations DB") raise e diff --git a/cogs/text_service_cog.py b/cogs/text_service_cog.py index e12b038..2f29ea4 100644 --- a/cogs/text_service_cog.py +++ b/cogs/text_service_cog.py @@ -49,8 +49,16 @@ MOD_DB = None GENERAL_DB = None try: print("Attempting to retrieve the General and Moderations DB") - MOD_DB = SqliteDict(EnvService.find_shared_file("main_db.sqlite"), tablename="moderations", autocommit=True) - GENERAL_DB = SqliteDict(EnvService.find_shared_file("main_db.sqlite"), tablename="general", autocommit=True) + MOD_DB = SqliteDict( + EnvService.find_shared_file("main_db.sqlite"), + tablename="moderations", + autocommit=True, + ) + GENERAL_DB = SqliteDict( + EnvService.find_shared_file("main_db.sqlite"), + tablename="general", + autocommit=True, + ) print("Retrieved the General and Moderations DB") except Exception as e: print("Failed to retrieve the General and Moderations DB. The bot is terminating.") diff --git a/models/index_model.py b/models/index_model.py index b631172..a84fb89 100644 --- a/models/index_model.py +++ b/models/index_model.py @@ -792,7 +792,7 @@ class Index_handler: ) # Save the composed index - tree_index.save_to_disk(app_root_path()/"indexes"/user_id/name) + tree_index.save_to_disk(app_root_path() / "indexes" / user_id / name) self.index_storage[user_id].queryable_index = tree_index @@ -822,7 +822,7 @@ class Index_handler: name = f"composed_index_{date.today().month}_{date.today().day}.json" # Save the composed index - simple_index.save_to_disk(app_root_path()/"indexes"/user_id/name) + simple_index.save_to_disk(app_root_path() / "indexes" / user_id / name) self.index_storage[user_id].queryable_index = simple_index try: