Skip to content
Snippets Groups Projects
Unverified Commit 9eeee707 authored by Kurt Thams's avatar Kurt Thams Committed by GitHub
Browse files

Docs/update slack demo colab (#10534)

parent 1ea5b233
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:40fd5c65 tags: %% Cell type:markdown id:40fd5c65 tags:
<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/data_connectors/SlackDemo.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> <a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/data_connectors/SlackDemo.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
%% Cell type:markdown id:effeb5a7-8544-4ee4-8c11-bad0d8165394 tags: %% Cell type:markdown id:effeb5a7-8544-4ee4-8c11-bad0d8165394 tags:
# Slack Reader # Slack Reader
Demonstrates our Slack data connector Demonstrates our Slack data connector
Requires a Slack Bot.
Here's a manafest that can be used to create the bot in your slack workspace
```yml
_metadata:
major_version: 1
minor_version: 1
display_information:
name: Slack Reader Bot
description: This bot will index channels for purposes of AI queries
features:
bot_user:
display_name: Slack Reader Bot
always_online: true
oauth_config:
scopes:
bot:
- channels:history
- channels:read
- groups:history
- groups:read
- im:history
- im:read
settings:
org_deploy_enabled: false
socket_mode_enabled: false
token_rotation_enabled: false
```
%% Cell type:markdown id:c19b997a tags: %% Cell type:markdown id:c19b997a tags:
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙. If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
%% Cell type:code id:222d4bce tags: %% Cell type:code id:222d4bce tags:
``` python ``` python
!pip install llama-index # venv required because conflicts with default Colab libraries
! apt install python3.10-venv
! python -m venv env
! source env/bin/activate
! pip install llama-index
! pip install slack-sdk
# and restart notebook.
``` ```
%% Cell type:code id:dc664882 tags: %% Cell type:code id:dc664882 tags:
``` python ``` python
import logging import logging
import sys import sys
import os
logging.basicConfig(stream=sys.stdout, level=logging.INFO) logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout)) logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
os.environ["SLACK_BOT_TOKEN"] = "xoxb-"
import openai
openai.api_key = "sk-" # OpenAI API key
``` ```
%% Cell type:code id:6ea1f66d-10ed-4417-bdcb-f8a894836ea5 tags: %% Cell type:code id:6ea1f66d-10ed-4417-bdcb-f8a894836ea5 tags:
``` python ``` python
from llama_index import SummaryIndex, SlackReader from llama_index import SummaryIndex
from llama_index.readers.slack import SlackReader
from IPython.display import Markdown, display from IPython.display import Markdown, display
import os
``` ```
%% Cell type:code id:da90589a-fb44-4ec6-9706-753dba4fa968 tags: %% Cell type:code id:da90589a-fb44-4ec6-9706-753dba4fa968 tags:
``` python ``` python
slack_token = os.getenv("SLACK_BOT_TOKEN") slack_token = os.getenv("SLACK_BOT_TOKEN")
channel_ids = ["<channel_id>"] channel_ids = [
"<channel_id>"
] # Find this in the URL of the channel; Right-click : Copy : Copy Link
documents = SlackReader(slack_token=slack_token).load_data( documents = SlackReader(slack_token=slack_token).load_data(
channel_ids=channel_ids channel_ids=channel_ids
) )
``` ```
%% Cell type:code id:341295df-2029-4728-ab3d-2ee178a7e6f1 tags: %% Cell type:code id:341295df-2029-4728-ab3d-2ee178a7e6f1 tags:
``` python ``` python
index = SummaryIndex.from_documents(documents) index = SummaryIndex.from_documents(documents)
``` ```
%% Cell type:code id:01c26b9d-49ec-4a6e-9c61-5c06bb86bbb2 tags: %% Cell type:code id:01c26b9d-49ec-4a6e-9c61-5c06bb86bbb2 tags:
``` python ``` python
# set Logging to DEBUG for more detailed outputs # set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine() query_engine = index.as_query_engine()
response = query_engine.query("<query_text>") response = query_engine.query("<query_text>")
``` ```
%% Cell type:code id:f160c678-2fb5-4d6d-b2bc-87abb61cfdec tags: %% Cell type:code id:f160c678-2fb5-4d6d-b2bc-87abb61cfdec tags:
``` python ``` python
display(Markdown(f"<b>{response}</b>")) display(Markdown(f"<b>{response}</b>"))
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment