The application is a Flask-based web server that integrates a Slack bot with a RAG (Retrieval-Augmented Generation) system for answering questions about uploaded PDF documents. It uses the Slack Bolt framework for handling Slack events and the custom RAGSystem for processing PDFs and answering questions.
A demonstration of this project can be viewed here.
Flask App: Handles web requests, including file uploads. Slack App: Manages Slack events and interactions. RAG System: Processes PDFs and answers questions based on their content.
- Clone your GitHub repository and navigate to the project directory.
- Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate` - Install the required dependencies:
pip install flask slack-bolt python-dotenv werkzeug langchain langchain-community langchain-openai langchain-chroma chromadb openai
- Download and install ngrok from https://ngrok.com/download
- Authenticate ngrok with your account token:
ngrok authtoken YOUR_AUTH_TOKEN
- Go to https://api.slack.com/apps and click "Create New App"
- Choose "From scratch" and give your app a name
- Select the workspace where you want to develop your app
- In the "Basic Information" section, note down your "Signing Secret"
- Go to "OAuth & Permissions" and add the following bot token scopes:
app_mentions:readchat:writechannels:history
- Install the app to your workspace
- Note down the "Bot User OAuth Token"
Create a .env file in your project root with the following content:
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_SIGNING_SECRET=your-signing-secret
SLACK_BOT_USER_ID=your-bot-user-id
OPENAI_API_KEY=your-openai-api-key
Replace the placeholders with your actual values. Note the addition of the OPENAI_API_KEY, which is required for the RAG system.
Make sure the pdflogic.py file (which imports RAGSystem) is also present and correctly implemented.
- Start your Flask server:
python app.py - In a new terminal, start ngrok:
ngrok http 5000 - Note the HTTPS URL provided by ngrok (e.g.,
https://1234-abcd-efgh.ngrok.io)
- Go to your Slack App's "Event Subscriptions" page
- Enable events and enter your ngrok URL +
/slack/eventsas the Request URL (e.g.,https://1234-abcd-efgh.ngrok.io/slack/events) - Subscribe to the
app_mentionbot event
- Invite your bot to a channel in your Slack workspace
- Upload a PDF: Access your ngrok URL in a web browser and use the upload form
- Ask questions: In Slack, mention your bot and start with
q!orquestion!, e.g.,@YourBot q! What's in the PDF?
- Upload a PDF: Access your ngrok URL in a web browser and use the upload form
- Ask questions: In Slack, mention your bot and start with
q!orquestion! - Get help: Mention your bot and type
help - Check status: Mention your bot and type
status
- Keep your
.envfile secure and never commit it to your repository. Add it to your.gitignorefile. - The ngrok URL changes each time you restart ngrok. Update your Slack App's Event Subscriptions URL when this happens.
- Ensure your Flask app is running on port 5000, as that's what the ngrok command is set up for.
- The RAG system uses OpenAI's GPT-4o-mini model. Make sure you have access to this model and sufficient API credits.
- The first question after uploading a PDF might take longer to answer as the system processes the document.
Remember to upload a PDF through the web interface before trying to ask questions about it in Slack.