Skip to content

Joaov41/reddit-chatbot

Repository files navigation

Reddit Flask Chatbot

A Flask application that interacts with Reddit and Gemini Flash to summarize posts and comments. Users can fetch the latest, hot, or top posts from a subreddit and get summaries.

Features

  • Fetch Reddit Posts: Retrieve new, hot, or top posts from any subreddit.

CleanShot 2025-01-24 at 19 59 35@2x

  • Summarize Posts and Comments: Get AI-generated summaries of posts and their comments.

    CleanShot 2025-01-24 at 20 00 36@2x

  • Chat Interface: Interact with the bot to ask questions about Reddit posts.

  • Overview function that does a general summary of the entirety of what is being discussed on an entire subreddit

CleanShot 2025-01-24 at 20 03 51@2x

CleanShot 2025-01-24 at 20 04 48@2x

Fixed a bug, where posts with with more than 200 comments would only extract up to 200 posts. Now the app extracts anad analyzes all comments, including all nested levels and the more comments api. It can handle ALL comments provided by the different Reddit api's. Switched from OpenAI to Gemini 2.0 Flash - very fast, with a very big context, essential for an app like this that handles huge amounts of text.

Technologies Used

  • Flask: Web framework for Python.
  • PRAW: Python Reddit API Wrapper.
  • Gemini API: For generating summaries using GPT models.
  • Flask-Session: Manage user sessions.
  • ** Implements LRU cache to avoid unnecessary repeated API calls.

Setup and Installation

1. Clone the Repository

git clone https://github.com/Joaov41/reddit-chatbot.git cd reddit-chatbot

2. Install Dependencies

pip install -r requirements.txt

3. Configure Environment Variables

Create a .env file from the example:

cp .env.example .env

Edit .env and add your API credentials:

4. Run the Application

python app.py

Recent Improvements

The codebase has been significantly improved with:

Security Enhancements

  • API credentials now stored in environment variables (not hardcoded)
  • Input validation and sanitization for all user inputs
  • Rate limiting to prevent API abuse
  • Secure session management

Performance Optimizations

  • Thread-safe LRU cache with TTL (time-to-live) support
  • Concurrent API calls for fetching multiple posts
  • Optimized memory usage

Code Quality

  • Modular architecture with separate services, models, and utilities
  • Type hints for better IDE support
  • Comprehensive error handling with specific exceptions
  • Clean separation of concerns

New Features

  • Health check endpoint (/health)
  • Better error messages with proper HTTP status codes
  • Enhanced caching strategy
  • Configurable rate limits

For users upgrading from an older version, please see the Migration Guide.

About

A Flask application that interacts with Reddit and OpenAI to summarize posts and comments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •