From 6283d9fe83a33bce00a0f0b19db328d1d228d636 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 21 Feb 2024 19:58:00 +0530 Subject: [PATCH] Update Khoj cloud trial period to a fortnight instead of a week - Improve rate limit error message wording - Make the "too many requests" error message more robust. Should throw that exception fix self.request >= self.subscribed_requests because upgrading wouldn't fix this rate limiting --- src/khoj/database/adapters/__init__.py | 2 +- src/khoj/routers/helpers.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/khoj/database/adapters/__init__.py b/src/khoj/database/adapters/__init__.py index da40f41f..c075700e 100644 --- a/src/khoj/database/adapters/__init__.py +++ b/src/khoj/database/adapters/__init__.py @@ -219,7 +219,7 @@ def subscription_to_state(subscription: Subscription) -> str: return SubscriptionState.INVALID.value elif subscription.type == Subscription.Type.TRIAL: # Trial subscription is valid for 7 days - if datetime.now(tz=timezone.utc) - subscription.created_at > timedelta(days=7): + if datetime.now(tz=timezone.utc) - subscription.created_at > timedelta(days=14): return SubscriptionState.EXPIRED.value return SubscriptionState.TRIAL.value diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index 0d4561b7..4fb3fa28 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -430,14 +430,14 @@ class ApiUserRateLimiter: if subscribed and count_requests >= self.subscribed_requests: raise HTTPException(status_code=429, detail="Slow down! Too Many Requests") if not subscribed and count_requests >= self.requests: - if self.subscribed_requests == self.requests: + if self.requests >= self.subscribed_requests: raise HTTPException( status_code=429, detail="Slow down! Too Many Requests", ) raise HTTPException( status_code=429, - detail="We're glad you're enjoying Khoj! You've exceeded your usage limit for today. Come back tomorrow or subscribe to increase your rate limit via [your settings](https://app.khoj.dev/config).", + detail="We're glad you're enjoying Khoj! You've exceeded your usage limit for today. Come back tomorrow or subscribe to increase your usage limit via [your settings](https://app.khoj.dev/config).", ) # Add the current request to the cache @@ -476,7 +476,7 @@ class ConversationCommandRateLimiter: if not subscribed and count_requests >= self.trial_rate_limit: raise HTTPException( status_code=429, - detail=f"We're glad you're enjoying Khoj! You've exceeded your `/{conversation_command.value}` command usage limit for today. You can increase your rate limit via [your settings](https://app.khoj.dev/config).", + detail=f"We're glad you're enjoying Khoj! You've exceeded your `/{conversation_command.value}` command usage limit for today. Subscribe to increase your usage limit via [your settings](https://app.khoj.dev/config).", ) await UserRequests.objects.acreate(user=user, slug=command_slug) return