Install | Download LLM | Create Discord Application | Configuration | Run
A basic Discord chatbot using Discord.py, LangChain, and GPT4ALL. The bot is designed to interact with Discord channel users in a conversational manner, leveraging large language models (LLMs), and conversational memory to provide engaging responses.
Important
- Requires atleast Python 3.10 to work
- Only tested on a GeForce GPU with 12GB of VRAM. Not sure if cards with less VRAM will work properly using the LLM referenced below.
conda update conda
conda create -n <env name> python=3.10
conda activate <env name>
mkdir <repo>
cd <repo>
git clone -n --depth=1 --filter=tree:0 https://github.com/shaunbarnard/python.git
cd python
4. Enable the sparse-checkout feature and specify the folder you want to clone (discord-llm-chatbot)
git sparse-checkout set --no-cone discord-llm-chatbot
git checkout
cd discord-llm-chatbot
pip install -r requirements.txt
Skip this section if you already have a model, otherwise head over to HuggingFace.co and choose a model to download.
If you have shitty internet, you're gonna want to create a custom download script to avoid wanting to punch a hole through your monitor...
sudo nano red.sh
#!/bin/bash
while true
do
wget -c --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 0 "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf?download=true"
sleep 10s
done
Note: If you need to replace the URL, make sure to include the '?download=true' parameter.
sudo chmod 775 red.sh
./red.sh
Note: The download script will contiunally retry and resume failed downloads, even if connection cuts out. Once download is complete, you'll need to manually kill the script.
sudo mv 'mistral-7b-v0.1.Q4_K_M.gguf?download=true' 'mistral-7b-v0.1.Q4_K_M.gguf'
- Log in to the Discord Developer Portal
- Click on the "New Application" button
- Give your application a name and confirm the creation
- Navigate to the "Bot" tab to configure the bot
- Check the "Public Bot" option if you want others to invite your bot
- Tick the "bot" checkbox under "scopes" and set the necessary permissions for your bot
- Copy the bot's token to use it in your bot's code
- Use the bot's token to invite the bot to your Discord server
- Set the appropriate permissions for your bot
Note: Above steps are a general overview of the process. For detailed instructions and best practices, you can refer to the Offical Discord Documentation
1. Set the model path in bot.py to your model's location.
#Set model path
model_path = ("mistral-7b-v0.1.Q4_K_M.gguf")
2. Adjust the remaining configuration settings in bot.py as necessary
BOT_PREFIX_ON = True
BOT_PREFIX = '/b'
BOT_CHANNEL_MESSAGE_ON = True
BOT_CHANNEL_MESSAGE = "Hey guys! Use '/b' followed by your message to interact with me ;)"
3. Paste your API Token into .env file
API_KEY=<your bot's discord token>
python bot.py