|
2 | 2 |
|
3 | 3 | This Bolt for Python template demonstrates how to build [AI Apps](https://docs.slack.dev/ai/) in Slack. |
4 | 4 |
|
| 5 | +Models from [OpenAI](https://openai.com) are used and can be customized for prompts of all kinds. |
| 6 | + |
5 | 7 | ## Setup |
| 8 | + |
6 | 9 | Before getting started, make sure you have a development workspace where you have permissions to install apps. If you don’t have one setup, go ahead and [create one](https://slack.com/create). |
7 | 10 |
|
8 | 11 | ### Developer Program |
| 12 | + |
9 | 13 | Join the [Slack Developer Program](https://api.slack.com/developer-program) for exclusive access to sandbox environments for building and testing your apps, tooling, and resources created to help you build and grow. |
10 | 14 |
|
11 | 15 | ## Installation |
12 | 16 |
|
13 | | -#### Create a Slack App |
| 17 | +Add this app to your workspace using either the Slack CLI or other development tooling, then read ahead to configuring LLM responses in the **[Providers](#providers)** section. |
| 18 | + |
| 19 | +### Using Slack CLI |
| 20 | + |
| 21 | +Install the latest version of the Slack CLI for your operating system: |
| 22 | + |
| 23 | +- [Slack CLI for macOS & Linux](https://docs.slack.dev/tools/slack-cli/guides/installing-the-slack-cli-for-mac-and-linux/) |
| 24 | +- [Slack CLI for Windows](https://docs.slack.dev/tools/slack-cli/guides/installing-the-slack-cli-for-windows/) |
| 25 | + |
| 26 | +You'll also need to log in if this is your first time using the Slack CLI. |
| 27 | + |
| 28 | +```sh |
| 29 | +slack login |
| 30 | +``` |
| 31 | + |
| 32 | +#### Initializing the project |
| 33 | + |
| 34 | +```sh |
| 35 | +slack create my-bolt-python-assistant --template slack-samples/bolt-python-assistant-template |
| 36 | +cd my-bolt-python-assistant |
| 37 | +``` |
| 38 | + |
| 39 | +#### Creating the Slack app |
| 40 | + |
| 41 | +Use the following command to add your new Slack app to your development workspace. Choose a "local" app environment for upcoming development: |
| 42 | + |
| 43 | +```sh |
| 44 | +slack install |
| 45 | +``` |
| 46 | + |
| 47 | +After the Slack app has been created you're all set to configure the LLM provider! |
| 48 | + |
| 49 | +### Using Terminal |
| 50 | + |
14 | 51 | 1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and choose "From an app manifest" |
15 | 52 | 2. Choose the workspace you want to install the application to |
16 | | -3. Copy the contents of [manifest.json](./manifest.json) into the text box that says `*Paste your manifest code here*` (within the JSON tab) and click *Next* |
17 | | -4. Review the configuration and click *Create* |
18 | | -5. Click *Install to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard. |
| 53 | +3. Copy the contents of [manifest.json](./manifest.json) into the text box that says `*Paste your manifest code here*` (within the JSON tab) and click _Next_ |
| 54 | +4. Review the configuration and click _Create_ |
| 55 | +5. Click _Install to Workspace_ and _Allow_ on the screen that follows. You'll then be redirected to the App Configuration dashboard. |
19 | 56 |
|
20 | | -### Environment Variables |
| 57 | +#### Environment Variables |
21 | 58 |
|
22 | 59 | Before you can run the app, you'll need to store some environment variables. |
23 | 60 |
|
24 | | - |
25 | 61 | 1. Rename `.env.sample` to `.env`. |
26 | 62 | 2. Open your apps setting page from [this list](https://api.slack.com/apps), click _OAuth & Permissions_ in the left hand menu, then copy the _Bot User OAuth Token_ into your `.env` file under `SLACK_BOT_TOKEN`. |
27 | | -```zsh |
| 63 | + |
| 64 | +```sh |
28 | 65 | SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN |
29 | 66 | ``` |
| 67 | + |
30 | 68 | 3. Click _Basic Information_ from the left hand menu and follow the steps in the _App-Level Tokens_ section to create an app-level token with the `connections:write` scope. Copy that token into your `.env` as `SLACK_APP_TOKEN`. |
31 | | -```zsh |
| 69 | + |
| 70 | +```sh |
32 | 71 | SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN |
33 | 72 | ``` |
34 | | -4. Save your OpenAI key into `.env` under `OPENAI_API_KEY`. |
35 | | -```zsh |
36 | | -OPENAI_API_KEY=YOUR_OPEN_API_KEY |
37 | | -``` |
38 | 73 |
|
| 74 | +#### Initializing the project |
39 | 75 |
|
40 | | -### Setup Your Local Project |
41 | | -```zsh |
42 | | -# Clone this project onto your machine |
43 | | -git clone https://github.com/slack-samples/bolt-python-assistant-template.git |
| 76 | +```sh |
| 77 | +git clone https://github.com/slack-samples/bolt-python-assistant-template.git my-bolt-python-assistant |
| 78 | +cd my-bolt-python-assistant |
| 79 | +``` |
44 | 80 |
|
45 | | -# Change into this project directory |
46 | | -cd bolt-python-assistant-template |
| 81 | +#### Setup your python virtual environment |
47 | 82 |
|
48 | | -# Setup your python virtual environment |
| 83 | +```sh |
49 | 84 | python3 -m venv .venv |
50 | 85 | source .venv/bin/activate # for Windows OS, .\.venv\Scripts\Activate instead should work |
| 86 | +``` |
51 | 87 |
|
52 | | -# Install the dependencies |
| 88 | +#### Install dependencies |
| 89 | + |
| 90 | +```sh |
53 | 91 | pip install -r requirements.txt |
| 92 | +``` |
| 93 | + |
| 94 | +## Providers |
| 95 | + |
| 96 | +### OpenAI Setup |
| 97 | + |
| 98 | +Unlock the OpenAI models from your OpenAI account dashboard by clicking [create a new secret key](https://platform.openai.com/api-keys), then save your OpenAI key into the `.env` file as `OPENAI_API_KEY` like so: |
| 99 | + |
| 100 | +```zsh |
| 101 | +OPENAI_API_KEY=YOUR_OPEN_API_KEY |
| 102 | +``` |
| 103 | + |
| 104 | +## Development |
| 105 | + |
| 106 | +### Starting the app |
| 107 | + |
| 108 | +#### Slack CLI |
54 | 109 |
|
55 | | -# Start your local server |
| 110 | +```sh |
| 111 | +slack run |
| 112 | +``` |
| 113 | + |
| 114 | +#### Terminal |
| 115 | + |
| 116 | +```sh |
56 | 117 | python3 app.py |
57 | 118 | ``` |
58 | 119 |
|
59 | 120 | Start talking to the bot! Start a new DM or thread and click the feedback button when it responds. |
60 | 121 |
|
61 | | -#### Linting |
62 | | -```zsh |
| 122 | +### Linting |
| 123 | + |
| 124 | +```sh |
63 | 125 | # Run ruff check from root directory for linting |
64 | 126 | ruff check |
65 | 127 |
|
@@ -88,7 +150,8 @@ Configures the new Slack Assistant features, providing a dedicated side panel UI |
88 | 150 | - The `assistant_thread_started.py` file, which responds to new app threads with a list of suggested prompts. |
89 | 151 | - The `message.py` file, which responds to user messages sent to app threads or from the **Chat** and **History** tab with an LLM generated response. |
90 | 152 |
|
91 | | -### `ai/` |
| 153 | +### `/ai` |
| 154 | + |
92 | 155 | The `llm_caller.py` file, which handles OpenAI API integration and message formatting. It includes the `call_llm()` function that sends conversation threads to OpenAI's models. |
93 | 156 |
|
94 | 157 | ## App Distribution / OAuth |
|
0 commit comments