llama-index readers reddit integration
Project description
Reddit Reader
pip install llama-index-readers-reddit
For any subreddit(s) you're interested in, search for relevant posts using keyword(s) and load the resulting text in the post and and top-level comments into LLMs/ LangChains.
Get your Reddit credentials ready
- Visit Reddit App Preferences (https://www.reddit.com/prefs/apps) or https://old.reddit.com/prefs/apps/
- Scroll to the bottom and click "create another app..."
- Fill out the name, description, and redirect url for your app, then click "create app"
- Now you should be able to see the personal use script, secret, and name of your app. Store those as environment variables REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, and REDDIT_USER_AGENT respectively.
- Additionally store the environment variables REDDIT_USERNAME and REDDIT_PASSWORD, which correspond to the credentials for your Reddit account.
Usage
LlamaIndex
from llama_index.core import VectorStoreIndex, download_loader
from llama_index.readers.reddit import RedditReader
subreddits = ["MachineLearning"]
search_keys = ["PyTorch", "deploy"]
post_limit = 10
loader = RedditReader()
documents = loader.load_data(
subreddits=subreddits, search_keys=search_keys, post_limit=post_limit
)
index = VectorStoreIndex.from_documents(documents)
index.query("What are the pain points of PyTorch users?")
LangChain
from llama_index.core import VectorStoreIndex, download_loader
from langchain.agents import initialize_agent, Tool
from langchain.llms import OpenAI
from langchain.chains.conversation.memory import ConversationBufferMemory
from llama_index.readers.reddit import RedditReader
subreddits = ["MachineLearning"]
search_keys = ["PyTorch", "deploy"]
post_limit = 10
loader = RedditReader()
documents = loader.load_data(
subreddits=subreddits, search_keys=search_keys, post_limit=post_limit
)
index = VectorStoreIndex.from_documents(documents)
tools = [
Tool(
name="Reddit Index",
func=lambda q: index.query(q),
description=f"Useful when you want to read relevant posts and top-level comments in subreddits.",
),
]
llm = OpenAI(temperature=0)
memory = ConversationBufferMemory(memory_key="chat_history")
agent_chain = initialize_agent(
tools, llm, agent="zero-shot-react-description", memory=memory
)
output = agent_chain.run(input="What are the pain points of PyTorch users?")
print(output)
This loader is designed to be used as a way to load data into GPT Index.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file llama_index_readers_reddit-0.3.0.tar.gz
.
File metadata
- Download URL: llama_index_readers_reddit-0.3.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aabd7a6c042d5752967ad7f081c141c07c61c3c0603229b2681e9b289f6c64a8 |
|
MD5 | 451269a6273286ca4e799517f34a0940 |
|
BLAKE2b-256 | f2a4d894de911e8cc787820e2cdf0ba9ee04b6c0d556b6c60483edaebe0f5c70 |
File details
Details for the file llama_index_readers_reddit-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: llama_index_readers_reddit-0.3.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.10 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a244370c22dc3e6e1ad2a1fee715c39d05c3de9780adeb2a6df297f24c7a8dea |
|
MD5 | 20694e36eec3c2de3b0f53d60ff96b2a |
|
BLAKE2b-256 | a0e8962091abdbbf3751a59c10864a4ebf60a6851310fd58f152068d8482673d |