Skip to content

An AI FAQ Bot that utilizes RAG for the NJIT Capstone Course Discord server

Notifications You must be signed in to change notification settings

gabrielpnjit/Capstone-FAQ-ChatBot

Repository files navigation

🤖Capstone FAQ Discord Bot❔

About

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!:

image

Setup

Below is how to setup the entire project

Langchain RAG-Pinecone Setup

*Requires Python Version 3.11+

1. pip install:

  • $ pip install --upgrade langchain langchain-cli langchain-pinecone langchain-openai langchain-cohere
  • Navigate to "rag-app" directory and execute $ pip install .

2. Set Environment Variables

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]'

3. Pinecone Documents:

  • 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.

4. Start Langserve

5. Editing rag-pinecone package

  • 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

Discord Bot Setup

1. Create Discord Bot Application

  • 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 the config.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 the config.json file image

2. Invite Bot to Server

  • 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 image
  • The bot should now be in the server

3. Configure config.json

  • In the node-js-bot directory, create a file called config.json with the same contents from config-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,
    • Click "Connect" on the desired cluster
    • Click "Drivers"
    • Copy the URI strin at the bottom, and replace and with your username and password image

4. Deploy Commands

  • Install the necessary node modules with $ npm install
  • Run $ node deploy-commands.js to deploy all the commands to the bot

5. Run The Bot

  • You can now run the bot with $ node index.js

Dashboard Site Setup - MERN

* Node Version 20.12+ required!

Backend (Express + MongoDB + Pinecone)

  1. $ cd into the server/ directory
  2. Run $ npm install
  3. Create config.env file with same variables as in config.env.template file, and replace the corresponding values (you can ignore the 4 AUTH0 values for now)
  4. Run the server with $ node --env-file=config.env server.js

Frontend (React + Vite)

  1. $ cd into the client/ directory
  2. Run $ npm install
  3. Run $ npm run dev