Skip to content

GintasS/discord-bot-chat-gpt-identify-harmful-content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Bot: Identify Harmful messages by ChatGPT LLM.

license

Table of Contents

About

It's a Discord bot designed to identify harmful messages using a ChatGPT. The bot listens to messages in Discord channels and categorizes them based on their content. If a message is identified as harmful, it is further classified into specific harmful categories and stored in a database for further analysis.

The bot is designed to help maintain a safe and healthy environment in Discord communities by automatically identifying and categorizing harmful messages, allowing for timely intervention and analysis.

Built With

The project uses these technologies:

  • Discord.py: A Python wrapper for the Discord API, enabling the bot to interact with Discord servers and process messages.
  • SQLAlchemy: An SQL toolkit and Object-Relational Mapping (ORM) library for Python, used to interact with the database where harmful messages are stored.
  • Pandas: A powerful data manipulation and analysis library for Python, used to process and analyze the data collected by the bot.
  • Logging: Python's built-in logging module is used to track the bot's activities and debug issues.
  • BAML: A library for managing and generating code, ensuring that the bot's codebase remains clean and maintainable.
  • Marshmallow: A library for object serialization and deserialization, used to convert database entities to and from Python objects.

Getting Started

Prerequisites

It is recommended to use VS Code or Cursor for this project. Python version that was used to develop the project: 3.9.13

Usage

Manual setup

Please follow these steps for manual setup: 0. Set-up the Discord bot on the Discord Developer Portal and add it to your server.

  1. Download this GitHub repository.
  2. Create a virtual environment.
python3 -m venv <myenvname>
  1. Activate virtual environment.
cd venv
Scripts\Activate.ps1

Or different Activate script, if you are not working from Visual Code.

  1. Install packages from requirements.txt
pip install -r /path/to/requirements.txt
  1. Replace environment variables with your PostgreSQL/Discord API credentials in the .env file.
    Replace CURRENT_ENVIRONMENT_NAME to use a correct environment (DEV for local machine, TEST for testing, PROD for AWS)

  2. Replace OPENAI_API_KEY in the baml_src/clients.baml with your own API KEY.

  3. (Optional) Install BAML Visual Code extension link This is super usefull if you're working with Visual Studio Code/Cursor IDEs.

We are using BAML library for working with Chat-GPT and other LLMs, enabling type-safety and rapid prototyping. More about BAML - here.

  1. CD into /app to generate .BAML code from the baml_src.
cd app
  1. Generate Python code from .BAML files.
baml-cli generate

This should create a folder baml_client with all of the python includes.

  1. Run the app.

Deploying to AWS

  1. Create a AWS RDS instance to host the PostgreSQL database.
  2. Make sure the program works, run at least once to check if the discord bot is running.
  3. In the .env file, change the CURRENT_ENVIRONMENT_NAME variable to use PROD .
  4. Run Docker command from the terminal to build an image:
docker build -t questions-answer-matcher-container .
  1. Run AWS CLI command to push the Docker Image:
aws lightsail push-container-image --service-name question-answer-matcher-service --label questions-answer-matcher-container --image questions-answer-matcher-container
  1. Change the containers.json in the app directory to use the latest image
question-answer-matcher-service.questions-answer-matcher-prodX.X
  1. Create an AWS deployment like this:
aws lightsail create-container-service-deployment --service-name question-answer-matcher-service --containers file://containers.json
  1. Check AWS Web UI for any errors.

Environment variables

in the .env file, replace these environment variables with your PostgreSQL database credentials.

Name Description
(TEST/DEV/PROD)_POSTGRES_DB_USER_NAME Database user name
(TEST/DEV/PROD)_POSTGRES_DB_PASSWORD Database password
(TEST/DEV/PROD)_POSTGRES_DB_URL URL of the PostgreSQL DB server
(TEST/DEV/PROD)_POSTGRES_DB_URL_PORT URL Port
(TEST/DEV/PROD)_POSTGRES_DB_NAME Database name
(TEST/DEV/PROD)_POSTGRES_DATABASE_URL A full replaced PostgreSQL DB URL for connection (DEV, TEST, PROD)
DISCORD_API_BOT_TOKEN Discord Bot's TOKEN
CURRENT_ENVIRONMENT_NAME Indicates what environment to use (DEV, TEST, PROD)

License

This project is licensed under the MIT license. Feel free to edit and distribute this template as you like.

See LICENSE for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages