Discord Reader¶
演示我们的 Discord 数据连接器
如果你在 Colab 上打开这个 Notebook,你可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
%pip install llama-index-readers-discord
%pip install llama-index-readers-discord
In [ ]
已复制!
!pip install llama-index
!pip install llama-index
In [ ]
已复制!
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
import logging import sys logging.basicConfig(stream=sys.stdout, level=logging.INFO) logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
In [ ]
已复制!
# This is due to the fact that we use asyncio.loop_until_complete in
# the DiscordReader. Since the Jupyter kernel itself runs on
# an event loop, we need to add some help with nesting
!pip install nest_asyncio
import nest_asyncio
nest_asyncio.apply()
# 这是因为我们在 DiscordReader 中使用了 asyncio.loop_until_complete。# 由于 Jupyter 内核本身运行在一个事件循环中,# 我们需要添加一些帮助来支持嵌套 !pip install nest_asyncio import nest_asyncio nest_asyncio.apply()
In [ ]
已复制!
from llama_index.core import SummaryIndex
from llama_index.readers.discord import DiscordReader
from IPython.display import Markdown, display
import os
from llama_index.core import SummaryIndex from llama_index.readers.discord import DiscordReader from IPython.display import Markdown, display import os
In [ ]
已复制!
discord_token = os.getenv("DISCORD_TOKEN")
channel_ids = [1057178784895348746] # Replace with your channel_id
documents = DiscordReader(discord_token=discord_token).load_data(
channel_ids=channel_ids
)
discord_token = os.getenv("DISCORD_TOKEN") channel_ids = [1057178784895348746] # 替换为你的 channel_id documents = DiscordReader(discord_token=discord_token).load_data( channel_ids=channel_ids )
In [ ]
已复制!
index = SummaryIndex.from_documents(documents)
index = SummaryIndex.from_documents(documents)
In [ ]
已复制!
# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("<query_text>")
# 将日志级别设置为 DEBUG 以获得更详细的输出 query_engine = index.as_query_engine() response = query_engine.query("")
In [ ]
已复制!
display(Markdown(f"<b>{response}</b>"))
display(Markdown(f"{response}"))