This bot is an automated customer sales representative designed for Discord servers. It uses a Retrieval-Augmented Generation (RAG) model to answer user queries based on the content of uploaded PDF files. The bot is built using discord.py
. It is simple to use and provides a seamless experience for server members looking for quick and accurate information.
- LLaMA3 Model Integration: Utilizes the LLaMA3-70B model for generating contextually relevant responses based on PDF content.
- LangChain Integration: Leverages LangChain for document processing, text splitting, and chaining responses.
- ChromaDB: Stores and retrieves document embeddings using ChromaDB for efficient similarity searches.
- Automated Support: Acts as a customer sales representative, providing detailed responses directly from PDFs.
- Discord Integration: Built using
discord.py
, making it easy to integrate and use within Discord servers.
- Python 3.11+
- pip (Python package installer)
- Create A Discord Bot and get its token (you can get this from the Discord Developer Portal)
- A Groq Api Key (you can get this from Groq Dashboard)
To use this bot in your Discord server, you'll first need to create a Discord bot through the Discord Developer Portal. Follow these steps to get started:
- Go to the Discord Developer Portal.
- Click on the "New Application" button.
- Enter a name for your application (e.g., "CSR Bot") and click "Create".
-
Select the bot tab from the menu
-
In the left-hand menu select Installation
-
Scroll down to the Guild Install section
-
Under Scopes, select
bot
andapplications.commands
. -
Under Permissions, select the following permissions:
Attach Files
Manage Channels
Manage Messages
Read Message History
Send Messages
Use Slash Commands
View Channels
View Audit Log
These permissions are essential for the bot to function properly within your server, allowing it to send and manage messages, view channels, and use slash commands.
-
Copy the Install Link open it in a new browser tab.
- Paste the Install Link you copied into your browser and press Enter.
- Choose the server you want to add the bot to from the dropdown list.
- Click "Authorize" and complete the CAPTCHA.
- In the Bot section, under "Token", click on "Reset Token" to generate a new token.
- Copy the token to a secure location; this token is your bot's password and should be kept secret.
- Your bot should be ready to use now.
-
Clone the repository:
git clone https://github.com/fiziqaiser/Discord-RAG-Bot.git cd Discord-RAG-Bot
-
Create a Python 3.11 virtual environment:
python3.11 -m venv venv
-
Activate the virtual environment:
-
On macOS and Linux:
source venv/bin/activate
-
On Windows:
venv\Scripts\activate
-
-
Install the required packages:
pip install -r requirements.txt
-
Set up the environment variables:
Rename the
example.env
file to.env
and fill in the following variables:TOKEN=your_discord_bot_token GROQ_API_KEY=your_api_key
-
Set up the configuration file:
Edit the
config.json
file to match your server's needs. For example:{ "bot_name": "CSR", "bot_image": "https://cdn.discordapp.com/attachments/1187679514684293181/1272568651563925524/images.png?ex=66bb7369&is=66ba21e9&hm=01cfab7d3ea7ffdde59b6b6b858a59bc277416d5b4aaddf53c61bb5cc21ebafe&", "prefix": ">>", "support_server_url": "https://discord.gg/kTavknSvrZ", "presence_activity": "to your queries.", "bot_primary_color": "3c76fa", "embed_footer": "Made with love by @fizzy.py" }
-
Run the bot:
python main.py
Once the bot is running, it will automatically sync commands with your Discord server. You can begin uploading PDFs and querying the bot immediately.
- Description: Upload a PDF file that the bot will use to answer queries.
- Usage:
/upload_file [file]
- Description: Query the bot with a question. The bot will respond based on the content of the uploaded PDF.
- Usage:
/query [your question]
The bot is highly configurable through the config.json
file. Here are some key settings:
bot_name
: The display name of the bot (default is "CSR").bot_image
: The URL for the bot's thumbnail image.prefix
: The command prefix for the bot (default is>>
).presence_activity
: The bot's presence status (default is "to your queries.").support_server_url
: Link to your support server for users to join if they need help.bot_primary_color
: The color used in embed messages (default is3c76fa
).embed_footer
: The footer text displayed in embed messages (default is "Made with love by @fizzy.py").
The bot includes a logging system that tracks important events such as when the bot joins or leaves a server. Logs are stored in a dedicated directory and can be customized in the code.
Contributions are welcomed from the community. If you'd like to contribute, please fork the repository and submit a pull request with your changes. Make sure to follow the project's coding standards and conventions.