Skip to main content

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 top-level comments into LLMs/ LangChains.

Get your Reddit credentials ready

  1. Visit Reddit App Preferences (https://www.reddit.com/prefs/apps) or https://old.reddit.com/prefs/apps/
  2. Scroll to the bottom and click "create another app..."
  3. Fill out the name, description, and redirect url for your app, then click "create app"
  4. 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.
  5. 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

llama_index_readers_reddit-0.5.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_readers_reddit-0.5.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_readers_reddit-0.5.0.tar.gz.

File metadata

  • Download URL: llama_index_readers_reddit-0.5.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_readers_reddit-0.5.0.tar.gz
Algorithm Hash digest
SHA256 226fa53e20a98eabbc747fd825995249dda2d5748e5457446a659896127b271f
MD5 0858fe5d7c0c7851de874a8d5f7bc9f9
BLAKE2b-256 97cf7ff9eb7d002e834037c6f314890599ae9cbb79a08a7f4115497badd7e77c

See more details on using hashes here.

File details

Details for the file llama_index_readers_reddit-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_readers_reddit-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_readers_reddit-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ecf35357203f634ae4321df3a5bed019558335798eef401b8ed4556c4cbbd37
MD5 3a54b95a0446c965d177c57725394d29
BLAKE2b-256 ae8b84e0161ab3c22b539ae3be041d36f79329ee6dd1decff5f1b00c562b48ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page