mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39:12 +00:00
Add more log lines when encountering rate limiting
This commit is contained in:
@@ -27,6 +27,7 @@ from khoj.database.models import (
|
||||
Subscription,
|
||||
TextToImageModelConfig,
|
||||
UserConversationConfig,
|
||||
UserRequests,
|
||||
UserSearchModelConfig,
|
||||
UserVoiceModelConfig,
|
||||
VoiceModelOption,
|
||||
@@ -103,6 +104,7 @@ admin.site.register(NotionConfig)
|
||||
admin.site.register(UserVoiceModelConfig)
|
||||
admin.site.register(VoiceModelOption)
|
||||
admin.site.register(UserConversationConfig)
|
||||
admin.site.register(UserRequests)
|
||||
|
||||
|
||||
@admin.register(Agent)
|
||||
|
||||
@@ -66,7 +66,7 @@ from khoj.utils.rawconfig import FileFilterRequest, FilesFilterRequest, Location
|
||||
# Initialize Router
|
||||
logger = logging.getLogger(__name__)
|
||||
conversation_command_rate_limiter = ConversationCommandRateLimiter(
|
||||
trial_rate_limit=100, subscribed_rate_limit=100, slug="command"
|
||||
trial_rate_limit=100, subscribed_rate_limit=6000, slug="command"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1029,13 +1029,23 @@ class ApiUserRateLimiter:
|
||||
|
||||
# Check if the user has exceeded the rate limit
|
||||
if subscribed and count_requests >= self.subscribed_requests:
|
||||
logger.info(
|
||||
f"Rate limit: {count_requests} requests in {self.window} seconds for user: {user}. Limit is {self.subscribed_requests} requests."
|
||||
)
|
||||
raise HTTPException(status_code=429, detail="Slow down! Too Many Requests")
|
||||
if not subscribed and count_requests >= self.requests:
|
||||
if self.requests >= self.subscribed_requests:
|
||||
logger.info(
|
||||
f"Rate limit: {count_requests} requests in {self.window} seconds for user: {user}. Limit is {self.subscribed_requests} requests."
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=429,
|
||||
detail="Slow down! Too Many Requests",
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Rate limit: {count_requests} requests in {self.window} seconds for user: {user}. Limit is {self.subscribed_requests} 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 usage limit via [your settings](https://app.khoj.dev/settings).",
|
||||
@@ -1073,6 +1083,9 @@ class ConversationCommandRateLimiter:
|
||||
).acount()
|
||||
|
||||
if subscribed and count_requests >= self.subscribed_rate_limit:
|
||||
logger.info(
|
||||
f"Rate limit: {count_requests} requests in 24 hours for user: {user}. Limit is {self.subscribed_rate_limit} requests."
|
||||
)
|
||||
raise HTTPException(status_code=429, detail="Slow down! Too Many Requests")
|
||||
if not subscribed and count_requests >= self.trial_rate_limit:
|
||||
raise HTTPException(
|
||||
|
||||
Reference in New Issue
Block a user