This repo contains all components of the Capstone FAQ Discord Bot:
- RAG Langchain Endpoint
- Discord Bot
- Dashboard Website
The goal of the Capstone FAQ Discord Bot is to answer various questions related to NJIT's CS491 Capstone Course. with the ability for the bot to "learn" by adjusting its knowledge base.
The bot utilizes retrieval-augmental generation (RAG) and OpenAI's Gpt-3.5 LLM to generate responses.
The bot in action!:
Below is how to setup the entire project
*Requires Python Version 3.11+
$ pip install --upgrade langchain langchain-cli langchain-pinecone langchain-openai langchain-cohere
- Navigate to "rag-app" directory and execute
$ pip install .
The following commands are used in a Linux/Unix Shell:
$ export OPENAI_API_KEY=[KEY HERE]
$ export PINECONE_API_KEY=[KEY HERE]
$ export PINECONE_ENVIRONMENT=[PINECONE ENVIRONMENT HERE]
- Your Pinecone environment, found in the Pinecone console, e.g. us-west1-gcp, us-east-1-aws, etc.
$ export PINECONE_INDEX=[PINECONE INDEX NAME HERE]
$ COHERE_API_KEY=[COHERE API KEY HERE]
If using Microsoft PowerShell:
$Env:OPENAI_API_KEY = '[KEY HERE]'
$Env:PINECONE_API_KEY = '[KEY HERE]'
$Env:PINECONE_ENVIRONMENT = '[PINECONE ENVIRONMENT HERE]'
$Env:PINECONE_INDEX = '[PINECONE INDEX NAME HERE]'
$Env:COHERE_API_KEY = '[COHERE API KEY HERE]'
- Go to rag-app\packages\rag-pinecone\rag_pinecone\chain.py
from langchain_community.document_loaders.csv_loader import CSVLoader
# from langchain_community.document_loaders import Docx2txtLoader
# from langchain_community.document_loaders import UnstructuredPowerPointLoader
# from langchain_community.document_loaders import PyPDFLoader
# from langchain_community.document_loaders import TextLoader
loader = CSVLoader("packages/rag-pinecone/documents/capstone-schedule.csv")
docs = loader.load()
- Adjust these lines to load the documents into the pinecone database that you want to use. Make sure to use the appropriate document loader.
- Don't run this code for the same document multiple times because it will create duplicate entries into the pinecone database, as well as use up OpenAI tokens because of the embedding.
- In rag-app directory:
$ langchain serve
- Playground: http://localhost:8000/rag-pinecone/playground/
- Whenever you make changes in the rag-pinecone package, specifically to the chain.py file, you must run
$ pip install . --force-reinstall
to apply the changes. - You made need to run
$ pip cache purge
first
- Login to Discord Developer Website
- Click "New Application" button on the top right and name and create your bot
- Note down "APPICATION ID" this will be the
"clientId"
in theconfig.json
file - Go to the "Bot" page in the navigation bar
- Under "Privileged Gateway Intents" enable all intents and save changes
- PRESENCE INTENT
- SERVER MEMBERS INTENT
- MESSAGE CONTENT INTENT
- Under the "Bot" page, click the "Reset Token" button and copy the newly generated token. This will be the
"token"
in theconfig.json
file
- Go to the "Installation" page in the navigation bar on the left
- Under "Authorization Methods", ensure only "Guild Install" is checked.
- Under "Install Link", select "Discord Provided Link"
- Under "Default Install Settings" add "bot" under the scopes
- Under "Permissions" select:
- Manage Messages
- Read Message History
- Read Messages/View Channels
- Send Messages
- Send Messages in Threads
- Use Slash Commands
- Copy the "Install Link" and visit the URL to invite the bot to your selected server
- The bot should now be in the server
- In the
node-js-bot
directory, create a file calledconfig.json
with the same contents fromconfig-template.json
{
"clientId": "CLIENT_ID_HERE",
"guildId": "GUILD_ID_HERE",
"token": "BOT_TOKEN_HERE",
"ATLAS_URI": "ATLAS_URI_HERE"
}
- Edit the values
"clientId"
: Refer to step 1"guildId"
: Right Click on Desired Server Icon > Click Copy Server ID"token"
: Refer to step 1"ATLAS_URI"
: Go to Database Deployments,
- Install the necessary node modules with
$ npm install
- Run
$ node deploy-commands.js
to deploy all the commands to the bot
- You can now run the bot with
$ node index.js
* Node Version 20.12+ required!
$ cd
into theserver/
directory- Run
$ npm install
- Create
config.env
file with same variables as inconfig.env.template
file, and replace the corresponding values (you can ignore the 4 AUTH0 values for now) - Run the server with
$ node --env-file=config.env server.js
$ cd
into theclient/
directory- Run
$ npm install
- Run
$ npm run dev