mirror of
https://github.com/StanGirard/quivr.git
synced 2024-11-23 12:26:03 +03:00
fix: 🐛 usage (#2062)
fixed where monthly was used in daily # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
e5d8d0f621
commit
54eb76da25
@ -229,6 +229,22 @@ class UserUsage(Repository):
|
||||
)
|
||||
return requests_stats.data
|
||||
|
||||
def get_user_requests_count_for_day(self, user_id, date):
|
||||
"""
|
||||
Fetch the user request count from the database
|
||||
"""
|
||||
response = (
|
||||
self.db.from_("user_daily_usage")
|
||||
.select("daily_requests_count")
|
||||
.filter("user_id", "eq", user_id)
|
||||
.filter("date", "eq", date)
|
||||
.execute()
|
||||
).data
|
||||
|
||||
if response and len(response) > 0:
|
||||
return response[0]["daily_requests_count"]
|
||||
return 0
|
||||
|
||||
def get_user_requests_count_for_month(self, user_id, date):
|
||||
"""
|
||||
Fetch the user request count from the database
|
||||
@ -244,20 +260,17 @@ class UserUsage(Repository):
|
||||
).data
|
||||
|
||||
if response and len(response) > 0:
|
||||
logger.info("🔥🔥🔥🔥🔥")
|
||||
logger.info(response)
|
||||
return sum(row["daily_requests_count"] for row in response)
|
||||
return 0
|
||||
|
||||
def increment_user_request_count(
|
||||
self, user_id, date, current_requests_count: int, number: int = 1
|
||||
):
|
||||
def increment_user_request_count(self, user_id, date, number: int = 1):
|
||||
"""
|
||||
Increment the user's requests count for a specific day
|
||||
"""
|
||||
current = self.get_user_requests_count_for_day(user_id, date)
|
||||
|
||||
self.update_user_request_count(
|
||||
user_id, daily_requests_count=current_requests_count + number, date=date
|
||||
user_id, daily_requests_count=current + number, date=date
|
||||
)
|
||||
|
||||
def update_user_request_count(self, user_id, daily_requests_count, date):
|
||||
|
@ -71,8 +71,10 @@ class UserUsage(UserIdentity):
|
||||
current_requests_count = self.supabase_db.get_user_requests_count_for_month(
|
||||
self.id, date
|
||||
)
|
||||
|
||||
logger.info("🔥🔥🔥🔥🔥🔥🔥🔥")
|
||||
logger.info(current_requests_count)
|
||||
if current_requests_count == 0:
|
||||
logger.info("Request count is 0, creating new record")
|
||||
if self.email is None:
|
||||
raise ValueError("User Email should be defined for daily usage table")
|
||||
self.supabase_db.create_user_daily_usage(
|
||||
@ -84,7 +86,6 @@ class UserUsage(UserIdentity):
|
||||
self.supabase_db.increment_user_request_count(
|
||||
user_id=self.id,
|
||||
date=date,
|
||||
current_requests_count=current_requests_count,
|
||||
number=number,
|
||||
)
|
||||
|
||||
|
@ -2,9 +2,12 @@ import time
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import HTTPException
|
||||
from logger import get_logger
|
||||
from models import UserUsage
|
||||
from modules.user.entity.user_identity import UserIdentity
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class NullableUUID(UUID):
|
||||
@classmethod
|
||||
@ -33,6 +36,11 @@ def check_user_requests_limit(user: UserIdentity, model: str):
|
||||
models_price = userDailyUsage.get_model_settings()
|
||||
user_choosen_model_price = 1000
|
||||
|
||||
# Log all info
|
||||
logger.info(
|
||||
f"User {user.id} with email {user.email} has {monthly_chat_credit} monthly chat credit and has used {daily_user_count} requests today."
|
||||
)
|
||||
logger.info("🔥🔥")
|
||||
for model_setting in models_price:
|
||||
if model_setting["name"] == model:
|
||||
user_choosen_model_price = model_setting["price"]
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user