basics of AI provider system

This commit is contained in:
vabene1111
2025-09-05 21:36:43 +02:00
parent 5572833f64
commit 41f0060c43
24 changed files with 1346 additions and 31 deletions

View File

@@ -0,0 +1,18 @@
from django.utils import timezone
from django.db.models import Sum
from cookbook.models import AiLog
def get_monthly_token_usage(space):
"""
returns the number of credits the space has used in the current month
"""
return AiLog.objects.filter(space=space, credits_from_balance=False, created_at__month=timezone.now().month).aggregate(Sum('credit_cost'))['credit_cost__sum']
def has_monthly_token(space):
"""
checks if the monthly credit limit has been exceeded
"""
return get_monthly_token_usage(space) < space.ai_credits_monthly