Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Llama Index
Commits
9eeee707
Unverified
Commit
9eeee707
authored
1 year ago
by
Kurt Thams
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Docs/update slack demo colab (#10534)
parent
1ea5b233
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/examples/data_connectors/SlackDemo.ipynb
+51
-7
51 additions, 7 deletions
docs/examples/data_connectors/SlackDemo.ipynb
with
51 additions
and
7 deletions
docs/examples/data_connectors/SlackDemo.ipynb
+
51
−
7
View file @
9eeee707
...
...
@@ -15,7 +15,36 @@
"metadata": {},
"source": [
"# Slack Reader\n",
"Demonstrates our Slack data connector"
"Demonstrates our Slack data connector\n",
"\n",
"Requires a Slack Bot. \n",
"Here's a manafest that can be used to create the bot in your slack workspace\n",
"\n",
"```yml\n",
"_metadata:\n",
" major_version: 1\n",
" minor_version: 1\n",
"display_information:\n",
" name: Slack Reader Bot\n",
" description: This bot will index channels for purposes of AI queries\n",
"features:\n",
" bot_user:\n",
" display_name: Slack Reader Bot\n",
" always_online: true\n",
"oauth_config:\n",
" scopes:\n",
" bot:\n",
" - channels:history\n",
" - channels:read\n",
" - groups:history\n",
" - groups:read\n",
" - im:history\n",
" - im:read\n",
"settings:\n",
" org_deploy_enabled: false\n",
" socket_mode_enabled: false\n",
" token_rotation_enabled: false\n",
"```"
]
},
{
...
...
@@ -34,7 +63,13 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index"
"# venv required because conflicts with default Colab libraries\n",
"! apt install python3.10-venv\n",
"! python -m venv env\n",
"! source env/bin/activate\n",
"! pip install llama-index\n",
"! pip install slack-sdk\n",
"# and restart notebook."
]
},
{
...
...
@@ -46,9 +81,16 @@
"source": [
"import logging\n",
"import sys\n",
"import os\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))\n",
"\n",
"os.environ[\"SLACK_BOT_TOKEN\"] = \"xoxb-\"\n",
"\n",
"import openai\n",
"\n",
"openai.api_key = \"sk-\" # OpenAI API key"
]
},
{
...
...
@@ -58,9 +100,9 @@
"metadata": {},
"outputs": [],
"source": [
"from llama_index import SummaryIndex
, SlackReader
\n",
"from
IPython.display import Markdown, display
\n",
"
import os
"
"from llama_index import SummaryIndex\n",
"from
llama_index.readers.slack import SlackReader
\n",
"
from IPython.display import Markdown, display
"
]
},
{
...
...
@@ -71,7 +113,9 @@
"outputs": [],
"source": [
"slack_token = os.getenv(\"SLACK_BOT_TOKEN\")\n",
"channel_ids = [\"<channel_id>\"]\n",
"channel_ids = [\n",
" \"<channel_id>\"\n",
"] # Find this in the URL of the channel; Right-click : Copy : Copy Link\n",
"documents = SlackReader(slack_token=slack_token).load_data(\n",
" channel_ids=channel_ids\n",
")"
...
...
%% 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>
%% Cell type:markdown id:effeb5a7-8544-4ee4-8c11-bad0d8165394 tags:
# Slack Reader
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:
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
%% Cell type:code id:222d4bce tags:
```
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:
```
python
import
logging
import
sys
import
os
logging
.
basicConfig
(
stream
=
sys
.
stdout
,
level
=
logging
.
INFO
)
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:
```
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
import
os
```
%% Cell type:code id:da90589a-fb44-4ec6-9706-753dba4fa968 tags:
```
python
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
(
channel_ids
=
channel_ids
)
```
%% Cell type:code id:341295df-2029-4728-ab3d-2ee178a7e6f1 tags:
```
python
index
=
SummaryIndex
.
from_documents
(
documents
)
```
%% Cell type:code id:01c26b9d-49ec-4a6e-9c61-5c06bb86bbb2 tags:
```
python
# set Logging to DEBUG for more detailed outputs
query_engine
=
index
.
as_query_engine
()
response
=
query_engine
.
query
(
"
<query_text>
"
)
```
%% Cell type:code id:f160c678-2fb5-4d6d-b2bc-87abb61cfdec tags:
```
python
display
(
Markdown
(
f
"
<b>
{
response
}
</b>
"
))
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment