Twitter 读取器¶
In [ ]
已复制!
%pip install llama-index-readers-twitter
%pip install llama-index-readers-twitter
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))
如果您在 colab 上打开此 Notebook,可能需要安装 LlamaIndex 🦙。
In [ ]
已复制!
!pip install llama-index
!pip install llama-index
In [ ]
已复制!
from llama_index.core import VectorStoreIndex
from llama_index.readers.twitter import TwitterTweetReader
from IPython.display import Markdown, display
import os
from llama_index.core import VectorStoreIndex from llama_index.readers.twitter import TwitterTweetReader from IPython.display import Markdown, display import os
In [ ]
已复制!
# create an app in https://developer.twitter.com/en/apps
BEARER_TOKEN = "<bearer_token>"
# 在 https://developer.twitter.com/en/apps 创建一个应用 BEARER_TOKEN = ""
In [ ]
已复制!
# create reader, specify twitter handles
reader = TwitterTweetReader(BEARER_TOKEN)
documents = reader.load_data(["@twitter_handle1"])
# 创建读取器,指定 Twitter 用户名 reader = TwitterTweetReader(BEARER_TOKEN) documents = reader.load_data(["@twitter_handle1"])
In [ ]
已复制!
index = VectorStoreIndex.from_documents(documents)
index = VectorStoreIndex.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}"))