iamge genration credits fixing - not fixed
This commit is contained in:
@@ -285,13 +285,13 @@ class CreditService:
|
||||
def check_credits_for_tokens(account, operation_type, estimated_tokens_input, estimated_tokens_output):
|
||||
"""
|
||||
Check if account has sufficient credits based on estimated token usage.
|
||||
|
||||
|
||||
Args:
|
||||
account: Account instance
|
||||
operation_type: Type of operation
|
||||
estimated_tokens_input: Estimated input tokens
|
||||
estimated_tokens_output: Estimated output tokens
|
||||
|
||||
|
||||
Raises:
|
||||
InsufficientCreditsError: If account doesn't have enough credits
|
||||
"""
|
||||
@@ -303,6 +303,36 @@ class CreditService:
|
||||
f"Insufficient credits. Required: {required}, Available: {account.credits}"
|
||||
)
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def check_credits_for_image(account, model_name: str, num_images: int = 1):
|
||||
"""
|
||||
Check if account has sufficient credits for image generation.
|
||||
|
||||
Args:
|
||||
account: Account instance
|
||||
model_name: AI model name (e.g., 'dall-e-3', 'runware:97@1')
|
||||
num_images: Number of images to generate
|
||||
|
||||
Raises:
|
||||
InsufficientCreditsError: If account doesn't have enough credits
|
||||
CreditCalculationError: If model not found or has no credits_per_image
|
||||
|
||||
Returns:
|
||||
int: Required credits for the operation
|
||||
"""
|
||||
required = CreditService.calculate_credits_for_image(model_name, num_images)
|
||||
|
||||
if account.credits < required:
|
||||
raise InsufficientCreditsError(
|
||||
f"Insufficient credits for image generation. Required: {required}, Available: {account.credits}"
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Credit check passed for image generation: "
|
||||
f"{num_images} images with {model_name} = {required} credits (available: {account.credits})"
|
||||
)
|
||||
return required
|
||||
|
||||
@staticmethod
|
||||
@transaction.atomic
|
||||
|
||||
Reference in New Issue
Block a user