ctp-slack-bot / README.md
KingZack's picture
updating port in Readme
75f0d24
|
raw
history blame
4.4 kB
metadata
app_port: 8080
title: CTP Slack Bot
emoji: 🦥
colorFrom: red
colorTo: green
sdk: docker
pinned: false
license: mit
short_description: Spring 2025 CTP Slack Bot RAG system

CTP Slack Bot

Modus Operandi in a Nutshell

  • Intelligently responds to Slack messages (when mentioned) based on a repository of data.
  • Periodically checks for new content to add to its repository.

How to Run the Application

You need to configure it first. This is done via environment variables, or an .env file based on the template, .env.template.

Obtaining the values requires setting up API tokens/secrets with:

  • Slack: for SLACK_BOT_TOKEN and SLACK_APP_TOKEN
  • MongoDB: for MONGODB_URI
  • OpenAI: for OPENAI_API_KEY
  • Google Drive: for GOOGLE_PROJECT_ID, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_EMAIL, GOOGLE_PRIVATE_KEY_ID, and GOOGLE_PRIVATE_KEY
    • For Google Drive, set up a service account. It’s the only supported authentication type.

Normally

Just run the Docker image. 😉

Build it with:

docker build . -t ctp-slack-bot

Run it with:

docker run --volume ./logs:/data --env-file=.env -p 8000:8000 --name my-ctp-slack-bot-instance ctp-slack-bot

For Development

Development usually requires rapid iteration. That means a change in the code ought to be reflected as soon as possible in the behavior of the application.

First, make sure you are set up with a Python virtual environment created by the Python venv module and that it’s activated. Then install dependencies from pyproject.toml within the environment using:

pip3 install -e .

Make a copy of .env.template as .env and define the environment variables. (You can also define them by other means, but this has the least friction.) This file should not be committed and is excluded by .gitignore!

If localhost port 8000 is free, running the following will make the application available on that port:

scripts/run-dev.sh

Tech Stack

  • Hugging Face Spaces for hosting
  • OpenAI for embeddings and language models
  • Google Drive for reference data (i.e., the material to be incorporated into the bot’s knowledge base)
  • MongoDB for data persistence
  • Docker for containerization
  • Python
    • Slack Bolt client for interfacing with Slack
    • See pyproject.toml for additional Python packages.

General Project Structure

  • src/
    • ctp_slack_bot/
      • core/: fundamental components like configuration (using pydantic), logging setup (loguru), and custom exceptions
      • db/: database connection
        • repositories/: repository pattern implementation
      • models/: Pydantic models for data validation and serialization
      • services/: business logic
        • answer_retrieval_service.py: obtains an answer to a question from a language model using relevant context
        • content_ingestion_service.py: converts content into chunks and stores them into the database
        • context_retrieval_service.py: queries for relevant context from the database to answer a question
        • embeddings_model_service.py: converts text to embeddings
        • event_brokerage_service.py: brokers events between decoupled components
        • language_model_service.py: answers questions using relevant context
        • question_dispatch_service.py: listens for questions and retrieves relevant context to get answers
        • schedule_service.py: runs background jobs
        • slack_service.py: handles events from Slack and sends back responses
        • vector_database_service.py: stores and queries chunks
        • vectorization_service.py: converts chunks into chunks with embeddings
      • tasks/: background scheduled jobs
      • utils/: reusable utilities
      • app.py: application entry point
      • containers.py: the dependency injection container
  • tests/: unit tests
  • scripts/: utility scripts for development, deployment, etc.
    • run-dev.sh: script to run the application locally
  • notebooks/: Jupyter notebooks for exploration and model development
  • .env: local environment variables for development purposes (to be created for local use only from .env.template)
  • Dockerfile: Docker container build definition
  • pyproject.toml: project definition and dependencies