Harrison/telegram chat loader (#4698)

Co-authored-by: Akinwande Komolafe <47945512+Sensei-akin@users.noreply.github.com>
Co-authored-by: Akinwande Komolafe <akhinoz@gmail.com>
This commit is contained in:
Harrison Chase
2023-05-14 22:04:27 -07:00
committed by GitHub
parent 2b181e5a6c
commit 12b4ee1fc7
4 changed files with 263 additions and 12 deletions

View File

@@ -19,7 +19,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.document_loaders import TelegramChatLoader"
"from langchain.document_loaders import TelegramChatFileLoader, TelegramChatApiLoader"
]
},
{
@@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"loader = TelegramChatLoader(\"example_data/telegram.json\")"
"loader = TelegramChatFileLoader(\"example_data/telegram.json\")"
]
},
{
@@ -41,7 +41,7 @@
{
"data": {
"text/plain": [
"[Document(page_content=\"Henry on 2020-01-01T00:00:02: It's 2020...\\n\\nHenry on 2020-01-01T00:00:04: Fireworks!\\n\\nGrace 🧤 ðŸ\\x8d on 2020-01-01T00:00:05: You're a minute late!\\n\\n\", lookup_str='', metadata={'source': 'example_data/telegram.json'}, lookup_index=0)]"
"[Document(page_content=\"Henry on 2020-01-01T00:00:02: It's 2020...\\n\\nHenry on 2020-01-01T00:00:04: Fireworks!\\n\\nGrace 🧤 ðŸ\\x8d on 2020-01-01T00:00:05: You're a minute late!\\n\\n\", metadata={'source': 'example_data/telegram.json'})]"
]
},
"execution_count": 3,
@@ -53,10 +53,45 @@
"loader.load()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "3e64cac2",
"metadata": {},
"source": [
"`TelegramChatApiLoader` loads data directly from any specified channel from Telegram. In order to export the data, you will need to authenticate your Telegram account. \n",
"\n",
"You can get the API_HASH and API_ID from https://my.telegram.org/auth?to=apps\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e64cac2",
"id": "f05f75f3",
"metadata": {},
"outputs": [],
"source": [
"loader = TelegramChatApiLoader(user_name =\"\"\\\n",
" chat_url=\"<CHAT_URL>\",\\\n",
" api_hash=\"<API HASH>\",\\\n",
" api_id=\"<API_ID>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40039f7b",
"metadata": {},
"outputs": [],
"source": [
"loader.load()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18e5af2b",
"metadata": {},
"outputs": [],
"source": []
@@ -78,7 +113,10 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.9.13"
}
},
"nbformat": 4,