Files
wehub-resource-sync a0c8464e58
Build Package / build (ubuntu-latest) (push) Failing after 1s
CodeQL / Analyze (python) (push) Failing after 1s
Core Typecheck / core-typecheck (push) Failing after 1s
Linting / lint (push) Failing after 1s
llama-dev tests / test-llama-dev (push) Failing after 1s
Publish Sub-Package to PyPI if Needed / publish_subpackage_if_needed (push) Has been skipped
Sync Docs to Developer Hub / sync-docs (push) Failing after 0s
Build Package / build (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:26:52 +08:00

175 lines
4.1 KiB
Plaintext

{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "40fd5c65",
"metadata": {},
"source": [
"<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",
"metadata": {},
"source": [
"# Slack Reader\n",
"Demonstrates our Slack data connector"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "c19b997a",
"metadata": {},
"source": [
"If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd09360b",
"metadata": {},
"outputs": [],
"source": [
"%pip install llama-index-readers-slack"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "222d4bce",
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc664882",
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"import sys\n",
"\n",
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
"logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ea1f66d-10ed-4417-bdcb-f8a894836ea5",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core import SummaryIndex\n",
"from llama_index.readers.slack import SlackReader\n",
"from IPython.display import Markdown, display\n",
"import os"
]
},
{
"cell_type": "markdown",
"id": "37145528-0ea5-431b-9eba-fddca6f746a3",
"metadata": {},
"source": [
"Load data using Channel IDs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da90589a-fb44-4ec6-9706-753dba4fa968",
"metadata": {},
"outputs": [],
"source": [
"slack_token = os.getenv(\"SLACK_BOT_TOKEN\")\n",
"channel_ids = [\"<channel_id>\"]\n",
"documents = SlackReader(slack_token=slack_token).load_data(\n",
" channel_ids=channel_ids\n",
")"
]
},
{
"cell_type": "markdown",
"id": "043d0c9c-a3eb-4ebe-854c-fbdf80bf3f8b",
"metadata": {},
"source": [
"Load data using Channel Names/Regex Patterns"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bad6321a-238b-4662-9405-58945c77b385",
"metadata": {},
"outputs": [],
"source": [
"slack_token = os.getenv(\"SLACK_BOT_TOKEN\")\n",
"channel_patterns = [\"<channel_name>\", \"<regex_pattern>\"]\n",
"slack_reader = SlackReader(slack_token=slack_token)\n",
"channel_ids = slack_reader.get_channel_ids(channel_patterns=channel_patterns)\n",
"documents = slack_reader.load_data(channel_ids=channel_ids)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "341295df-2029-4728-ab3d-2ee178a7e6f1",
"metadata": {},
"outputs": [],
"source": [
"index = SummaryIndex.from_documents(documents)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "01c26b9d-49ec-4a6e-9c61-5c06bb86bbb2",
"metadata": {},
"outputs": [],
"source": [
"# set Logging to DEBUG for more detailed outputs\n",
"query_engine = index.as_query_engine()\n",
"response = query_engine.query(\"<query_text>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f160c678-2fb5-4d6d-b2bc-87abb61cfdec",
"metadata": {},
"outputs": [],
"source": [
"display(Markdown(f\"<b>{response}</b>\"))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}