Skip to content

Commit

Permalink
fix pr review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyobyb authored and oshoma committed Feb 14, 2024
1 parent 18f90fa commit e621320
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/.env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion src/sherpa_ai/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
5 changes: 3 additions & 2 deletions src/sherpa_ai/database/user_usage_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit e621320

Please sign in to comment.