From 3c50a0641972d2c68b43482cf9d89d9d2a6e1cec Mon Sep 17 00:00:00 2001 From: Eyobyb Date: Mon, 12 Feb 2024 11:55:27 +0300 Subject: [PATCH] fix pr review issues --- src/.env-sample | 2 +- src/sherpa_ai/config/__init__.py | 2 +- src/sherpa_ai/database/user_usage_tracker.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/.env-sample b/src/.env-sample index 622716d3..f6c9114f 100644 --- a/src/.env-sample +++ b/src/.env-sample @@ -38,5 +38,5 @@ SLACK_VERIFICATION_TOKEN= # from `Basic Information` page of your Slack # Github. Optional. # GITHUB_AUTH_TOKEN= # Authorization token for Github API -# USAGE LIMIT +# Language model usage limits. Optional. # DAILY_TOKEN_LIMIT # Daily limit on the number of tokens users can use. \ No newline at end of file diff --git a/src/sherpa_ai/config/__init__.py b/src/sherpa_ai/config/__init__.py index 2d50f01c..5dfa93bb 100644 --- a/src/sherpa_ai/config/__init__.py +++ b/src/sherpa_ai/config/__init__.py @@ -49,7 +49,7 @@ LOG_LEVEL = environ.get("LOG_LEVEL", "INFO").upper() # Usage setting -DAILY_TOKEN_LIMIT = float(environ.get("DAILY_TOKEN_LIMIT")) or 20000.00 +DAILY_TOKEN_LIMIT = float(environ.get("DAILY_TOKEN_LIMIT") or 20000) DAILY_LIMIT_REACHED_MESSAGE = ( environ.get("DAILY_LIMIT_REACHED_MESSAGE") or "Sorry for the inconvenience, but it seems that you have exceeded your daily token limit. As a result, you will need to try again after 24 hours. Thank you for your understanding." diff --git a/src/sherpa_ai/database/user_usage_tracker.py b/src/sherpa_ai/database/user_usage_tracker.py index 4b37eba9..b1389184 100644 --- a/src/sherpa_ai/database/user_usage_tracker.py +++ b/src/sherpa_ai/database/user_usage_tracker.py @@ -44,6 +44,7 @@ def __init__( self.max_daily_token = cfg.DAILY_TOKEN_LIMIT self.verbose_logger = verbose_logger self.is_reminded = False + self.usage_percentage_allowed = 75 def download_from_s3(self, bucket_name, s3_file_key, local_file_path): file_path = Path("./token_counter.db") @@ -118,13 +119,13 @@ def remind_user_of_daily_token_limit(self, combined_id): self.is_reminded = self.check_if_reminded(combined_id=combined_id) if not user_is_whitelisted and not self.is_reminded: if ( - self.percentage_used(combined_id=combined_id) > 75 + self.percentage_used(combined_id=combined_id) > self.usage_percentage_allowed and not self.is_reminded ): self.add_data(combined_id=combined_id, token=0, reminded_timestamp=True) self.verbose_logger.log( - "hi friend, you have used up 75% of your daily token limit. once you go over the limit there will be a 24 hour cool down period after which you can continue using Sherpa! be awesome!" + f"Hi friend, you have used up {self.usage_percentage_allowed}% of your daily token limit. once you go over the limit there will be a 24 hour cool down period after which you can continue using Sherpa! be awesome!" ) def get_data_since_last_reset(self, user_id):