Skip to content

adikal25/slack-tone-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slack-tone-bot

I built this out of pure laziness — I was tired of formatting my messages manually every single time, so I automated it into my slack workspace ;). (Will be working on context of previous chats in a session soon.)

Local Slack bot that reformats messages into your personal tone, running entirely on-device using MLX and a quantized Mistral 7B model.


Features

  • Personal tone rewriter: Takes any Slack message and rewrites it to match your configured style.
  • Two entry points:
    • /fmt slash command (ephemeral response).
    • DM the bot directly and it replies with a reformatted version.
  • Local-only LLM: Uses mlx-community/Mistral-7B-Instruct-v0.3-4bit via mlx-lm.
  • Configurable style: Tune persona, tone, and examples in config/style.yaml.

Project structure

  • src/slack_tone_bot/ — bot code (LLM wrapper, formatter, Slack Bolt app, entrypoint).
  • config/style.yaml — tone/style configuration (persona, sliders, guidelines, examples).
  • .env — Slack credentials and optional overrides (not committed; use .env.example as a template).

Entrypoint:

  • CLI script: slack-tone-bot (via pyproject.toml).
  • Module: python -m slack_tone_bot.main

Requirements

  • Python 3.11+
  • macOS with Apple Silicon recommended (for MLX performance)
  • Slack app with:
    • Bot token (SLACK_BOT_TOKEN)
    • App-level token (SLACK_APP_TOKEN, with connections:write for Socket Mode)

Python dependencies are managed via pyproject.toml and include:

  • slack-bolt, slack-sdk
  • mlx-lm
  • pydantic
  • PyYAML
  • python-dotenv

Setup

1. Clone and create a virtualenv

git clone <your-repo-url> slack-tone-bot
cd slack-tone-bot

python -m venv .venv
source .venv/bin/activate

2. Install in editable mode

pip install --upgrade pip
pip install -e .

For src/ layout projects like this one, using pip install -e . ensures slack_tone_bot is importable without manually tweaking PYTHONPATH.

3. Configure environment

Create a .env file in the project root (you can copy .env.example):

cp .env.example .env

Then fill in at least:

SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...

Optional overrides:

  • MODEL_NAME — MLX model name (default: mlx-community/Mistral-7B-Instruct-v0.3-4bit)
  • STYLE_CONFIG_PATH — path to a custom style YAML (default: config/style.yaml)

4. Customize the tone (optional but recommended)

Edit config/style.yaml to match your personal style:

  • persona — short description of how you communicate.
  • tone — sliders for formality, warmth, humor, energy, emoji usage, capitalization, sentence style.
  • guidelines — bullet rules like “keep messages short”, “avoid jargon”.
  • examples — input/output pairs the model should mimic.

Running the bot

Activate your virtualenv (if not already):

source .venv/bin/activate

Then start the bot:

python -m slack_tone_bot.main

On first run, MLX will download the model weights and initialize the tokenizer, which can take 10–20 seconds.

If the Slack tokens or style config path are missing/invalid, the process will log an error and exit.


Using the bot in Slack

  • Slash command: In any channel or DM where the bot is installed, run:

    /fmt I think we should maybe delay the deploy a bit until we understand the metrics better
    

    The bot replies ephemerally with a reformatted version in your tone.

  • Direct messages: DM the bot any text, and it will respond with a rewritten version:

    hey can we sync on this later this week
    

    → reformatted reply in your configured style.


Implementation notes

  • The system prompt is built from config/style.yaml via build_system_prompt and combined with the user message before sending to the LLM.
  • Inference is done through a small LocalLLM wrapper (mlx_lm.load + mlx_lm.generate) with a per-instance lock for basic thread safety.
  • The Slack app runs in Socket Mode via slack_bolt’s SocketModeHandler, with:
    • /fmt command for explicit rewrites.
    • message event handler for DMs.

Troubleshooting

  • Imports fail (ModuleNotFoundError: slack_tone_bot)

    • Ensure you ran pip install -e . inside the virtualenv.
    • Or, as a quick check: PYTHONPATH=src python -c "from slack_tone_bot.config import load_style_config; print('ok')"
  • Bot exits with “Missing SLACK_BOT_TOKEN or SLACK_APP_TOKEN”

    • Verify .env exists at the project root and the variables are set.
  • Slow first run

    • Model download and initialization are expected to be slow the first time. Subsequent runs should be faster.

Development tips

  • Activate the venv and run:

    source .venv/bin/activate
    python -m slack_tone_bot.main
  • To quickly verify that imports and config loading work:

    python -c "from slack_tone_bot.config import load_style_config; print('ok')"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages