Skip to content

Commit

Permalink
Add slack from main
Browse files Browse the repository at this point in the history
  • Loading branch information
tianjing-li committed Nov 1, 2024
2 parents ec2fcb0 + 404f286 commit c01c05c
Show file tree
Hide file tree
Showing 40 changed files with 795 additions and 64 deletions.
18 changes: 18 additions & 0 deletions .github/actions/assistants-web-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: js-install
description: Set up Node.js/npm, install dependencies

runs:
using: composite
steps:
- uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: "src/interfaces/assistants_web/.nvmrc"
cache: "npm"
cache-dependency-path: "src/interfaces/assistants_web/package-lock.json"

- name: Install dependencies with npm
shell: bash
working-directory: src/interfaces/assistants_web
run: npm ci
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check for duplicate revision IDs
name: Alembic - No duplicate IDs

on:
pull_request:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Automated Migrations
name: Alembic - Automate migrations
# This workflow provides a way to run Alembic migrations using SSH or migration API or database URL.
on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backend_integration_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend integration tests
name: Backend - Integration tests

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python Lint
name: Backend - Lint

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Typecheck newly added Python files
name: Backend - Typecheck new files

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backend_unit_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend unit tests
name: Backend - Unit tests

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker_push_backend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create and publish backend image
name: Backend - Create and publish Docker image

on:
release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker_push_frontend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create and publish frontend image
name: Frontend - Create and publish Docker image

on:
release:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/frontend_assistants_web_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Assistants Web - Format and build

on:
push:
branches: [main]
paths:
- src/interfaces/assistants_web/**
pull_request: {}
merge_group: {}

jobs:
interface_tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/interfaces/assistants_web
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up Node.js and install dependencies
uses: ./.github/actions/assistants-web-install
- name: Check assistants_web is formatted
run: npm run format
- name: Check assistants_web can build
run: npm run build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coral Web Tests
name: Coral Web - Format and build

on:
push:
Expand All @@ -20,7 +20,7 @@ jobs:
with:
fetch-depth: 2
- name: Set up Node.js and install dependencies
uses: ./.github/actions/js-install
uses: ./.github/actions/coral-web-install
- name: Check coral_web is formatted
run: npm run format
- name: Check coral_web can build
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Slack Bot Tests
name: Slack Bot - Format and build

on:
push:
Expand Down
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Toolkit is a deployable all-in-one RAG application that enables users to quickly
- [How to add tools](/docs/custom_tool_guides/tool_guide.md)
- [How to add auth to your tools](/docs/custom_tool_guides/tool_auth_guide.md)
- [How to setup Google Drive](/docs/custom_tool_guides/google_drive.md)
- [How to setup Slack Tool](/docs/custom_tool_guides/slack.md)
- [How to setup Google Text-to-Speech](/docs/text_to_speech.md)
- [How to add authentication](/docs/auth_guide.md)
- [How to deploy toolkit services](/docs/service_deployments.md)
Expand All @@ -24,22 +25,33 @@ Toolkit is a deployable all-in-one RAG application that enables users to quickly
![](/docs/assets/toolkit.gif)

## Try Now:
There are two main ways for quickly running Toolkit: local and cloud. See the specific instructions given below.
### Local
*You will need to have [Docker](https://www.docker.com/products/docker-desktop/) and [Docker-compose >= 2.22](https://docs.docker.com/compose/install/) installed. [Go here for a more detailed setup.](/docs/setup.md)*
Note: to include community tools when building locally, set the `INSTALL_COMMUNITY_DEPS` build arg in the `docker-compose.yml` to `true`.

*You will need to have [Docker](https://www.docker.com/products/docker-desktop/) and [Docker-compose >= 2.22](https://docs.docker.com/compose/install/) installed. [Go here for a more detailed setup.](/docs/setup.md)*
Both options will make the frontend available at http://localhost:4000.

There are two main ways of running Toolkit:
#### Using `make`
Use the provided Makefile to simplify and automate your development workflow with Cohere Toolkit, including Docker Compose management, testing, linting, and environment setup.
```bash
git clone https://github.com/cohere-ai/cohere-toolkit.git
cd cohere-toolkit
make first-run
```

**Docker Compose setup**

Note: to include community tools when building locally, set the `INSTALL_COMMUNITY_DEPS` build arg in the `docker-compose.yml` to `true`.

#### Docker Compose only
Use Docker Compose directly if you want to quickly spin up and manage your container environment without the additional automation provided by the Makefile.
```bash
git clone https://github.com/cohere-ai/cohere-toolkit.git
cd cohere-toolkit
make first-run
docker compose up
docker compose run --build backend alembic -c src/backend/alembic.ini upgrade head
```

## GitHub Codespaces
### Cloud
#### GitHub Codespaces

To run this project using GitHub Codespaces, please refer to our [Codespaces Setup Guide](/docs/github_codespaces.md).

Expand Down
131 changes: 131 additions & 0 deletions docs/custom_tool_guides/slack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Slack Tool Setup

To set up the Slack tool you will need a Slack application. Follow the steps below to set it up:

## 1. Create a Slack App

Head to the [Slack API](https://api.slack.com/apps) and create a new app.
After creating the app, you will see the `App Credentials` section. Copy the `Client ID` and `Client Secret` values.
That will be used for the environment variables specified above.

## 2. Set up OAuth & Permissions
OAuth flow is required to authenticate users with Slack.
To enable it please set the following redirect URL to your app's settings:
```bash
https://<your_backend_url>/v1/tool/auth
```
Please note that for the local development you will need to enable HTTPS.
See the [Setup HTTPS for Local Development](#5-setup-https-for-local-development) section for more details.
If you are using a local https setup, redirect url should be
```
https://localhost:8000/v1/tool/auth
```
Also, you can set up a proxy, such as [ngrok](https://ngrok.com/docs/getting-started/), to expose your local server to the internet.

The Slack tool uses User Token Scopes to access the user's Slack workspace.
The required and the default permission scope is `search:read`.
Set it in the `OAuth & Permissions` section of your Slack app settings.

To work with the Slack Tool Advanced token security via token rotation is required.
To enable it, go to the `OAuth & Permissions` section of your Slack app settings and click 'Opt in' button in the 'Advanced token security via token rotation' section.

More information about the OAuth flow can be found [here](https://api.slack.com/authentication/oauth-v2).

## 3. Set Up Environment Variables

Then set the following environment variables. You can either set the below values in your `secrets.yaml` file:
```bash
slack:
client_id: <your_client_id from step 1>
client_secret: <your_client_secret from step 1>
```
or update your `.env` configuration to contain:
```bash
SLACK_CLIENT_ID=<your_client_id from step 1>
SLACK_CLIENT_SECRET=<your_client_secret from step 1>
```

## 4. Enable the Slack Tool in the Frontend

To enable the Slack tool in the frontend, you will need to modify the `src/community/config/tools.py` file. Add the `TOOL_SLACK_ID` to the `AGENT_SETTINGS_TOOLS` list.

```typescript
export const AGENT_SETTINGS_TOOLS = [
TOOL_HYBRID_WEB_SEARCH_ID,
TOOL_PYTHON_INTERPRETER_ID,
TOOL_WEB_SCRAPE_ID,
TOOL_SLACK_ID,
];
```

To enable the Slack tool in the frontend for Base Agent, you will need to modify the `src/community/config/tools.py` file. Remove the `TOOL_SLACK_ID` from the `BASE_AGENT_EXCLUDED_TOOLS` list.
By default, the Slack Tool is disabled for the Base Agent. Also if you need to exclude some tool from the Base Agent just add it to the `BASE_AGENT_EXCLUDED_TOOLS` list.
```typescript
export const BASE_AGENT_EXCLUDED_TOOLS = [];
```

## 5. Setup HTTPS for Local Development

To enable HTTPS for local development, the self-signed certificate needs to be generated.
Run the following command in the project root directory to generate the certificate and key:

```bash
openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
```

Then, update the backend Docker configuration(src/backend/Dockerfile) to use the generated certificate.
Just change next lines in the Dockerfile:
```Dockerfile
COPY pyproject.toml poetry.lock cert.pem key.pem ./
```
and
```Dockerfile
CMD uvicorn backend.main:app --reload --host 0.0.0.0 --port ${PORT} --timeout-keep-alive 300 --ssl-keyfile /workspace/key.pem --ssl-certfile /workspace/cert.pem
```
Change NEXT_PUBLIC_API_HOSTNAME environment variable in the .env `https` protocol:
```bash
NEXT_PUBLIC_API_HOSTNAME=https://localhost:8000
```

or in the configurations.yaml file:

```yaml
auth:
backend_hostname: https://localhost:8000
```
To run the Frontend with HTTPS, update the `start` script in the `package.json` file:

```json
"scripts": {
"dev": "next dev --port 4000 --experimental-https",
..........
}
```

Add the following line to the 'docker-compose.yml' file to the frontend environment variables:

```yaml
NEXT_PUBLIC_API_HOSTNAME=https://localhost:8000
```

and change the API_HOSTNAME to

```yaml
API_HOSTNAME: https://localhost:8000
```
also change the src/interfaces/assistants_web/.env.development file env variables to use https.

## 6. Run the Backend and Frontend

run next command to start the backend and frontend:

```bash
make dev
```

## 7. Troubleshooting

If you encounter any issues with OAuth, please check the following [link](https://api.slack.com/authentication/oauth-v2#errors)
For example, if you see the invalid_team_for_non_distributed_app error,
please ensure the app is distributed or try logging in with the workspace owner's account.
Loading

0 comments on commit c01c05c

Please sign in to comment.