hackerai-tech / PentestGPT

AI-Powered Automated Penetration Testing Tool
https://pentestgpt.ai/
GNU General Public License v3.0
814 stars 32 forks source link

Implementing Message Rate Limits with Supabase for HackerGPT and GPT-4 Turbo Models #7

Closed RostyslavManko closed 8 months ago

RostyslavManko commented 8 months ago

Background

To manage our system resources efficiently and maintain a quality service, we are introducing rate limits on the number of messages users can send within a 3-hour period. This will be implemented using Supabase to store each user's message count for both HackerGPT and GPT-4 Turbo models. The rate limits will differ for Free and Plus users. Additionally, we aim to track the total number of messages sent each month for each model, and if feasible, the token usage as well. This implementation can take cues from our existing rate limit logic in this repository.

Objective

To establish a rate-limiting system that tracks and controls the number of messages sent by each user over a 3-hour period for both HackerGPT and GPT-4 Turbo models. This system should be adjustable and provide clear feedback to users when they reach their limit. Plus, it should maintain a monthly log of total messages and, optionally, token usage for each model.

Actions and Considerations (ACC)

  1. Rate Limit Logic Implementation:

    • [x] Develop rate limit logic in Supabase for both HackerGPT and GPT-4 Turbo models, ensuring different limits for Free and Plus users.
    • [x] Make the message limit easily adjustable for potential future changes.
  2. User Feedback and Notification:

    • [x] Create a mechanism to inform users when they hit their rate limit, using a template similar to:
      • For Free users:
        
        ⚠️ Hold On! You've Hit Your Usage Cap.
        ⏰ Don't worry—you'll be back in ${rateLimitStatus.timeRemaining}.
        🔓 Want more? Upgrade to Plus and unlock a world of features:
      • Enjoy unlimited usage,
      • Get exclusive access to GPT-4 Turbo,
      • Experience faster response speed,
      • Explore the web with our Web Browsing plugin,
      • Plus, get access to advanced hacking tools like Katana, HttpX, Naabu, and more.
      • For Plus users:
        ⚠️ Hold On! You've Hit Your Usage Cap.
        ⏰ Don't worry—you'll be back in ${rateLimitStatus.timeRemaining}.
  3. Testing and Quality Assurance:

    • [x] Test the rate-limiting system extensively to ensure accuracy and reliability.
    • [x] Validate the user notification system for different user types (Free and Plus).

Expected Outcomes

momonja3 commented 8 months ago

@thehackergpt Can we "Monthly Usage Tracking" to new separated issues? those issues are not related rate limits.

Monthly usage tracking can be achieved chats table without do anything. We will need to consider an UI design and navigation.

Optionally, include a feature to track the number of tokens used per model each month.

This issue requires a slightly more complex implementation. A bit large to include in this Issue.

RostyslavManko commented 8 months ago

@momonja3, sure, no problem. This was optional at the beginning, and we can work on it later if necessary. Let's focus on completing the essential tasks first.