Skip to content

Commit

Permalink
Revoke quota ability
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Feb 19, 2025
1 parent a231067 commit d9ac144
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ols/src/quota/quota_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class QuotaLimiter(ABC):
def available_quota(self, user_id: str) -> int:
"""Retrieve available quota for given user."""

@abstractmethod
def revoke_quota(self, user_id: str) -> None:
"""Revoke quota for given user."""

@abstractmethod
def consume_tokens(
self, user_id: str, input_tokens: int, output_tokens: int
Expand Down
12 changes: 12 additions & 0 deletions ols/src/quota/user_quota_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ def available_quota(self, user_id: str) -> int:
return self.initial_quota
return value[0]

def revoke_quota(self, user_id: str) -> None:
"""Revoke quota for given user."""
# timestamp to be used
updated_at = datetime.now()

with self.connection.cursor() as cursor:
cursor.execute(
UserQuotaLimiter.UPDATE_AVAILABLE_QUOTA_FOR_USER,
(self.initial_quota, updated_at, user_id),
)
self.connection.commit()

def consume_tokens(
self, user_id: str, input_tokens: int, output_tokens: int
) -> None:
Expand Down

0 comments on commit d9ac144

Please sign in to comment.