credits adn tokens final correct setup

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-20 00:36:23 +00:00
parent e041cb8e65
commit c17b22e927
13 changed files with 1170 additions and 233 deletions

View File

@@ -63,10 +63,14 @@ class LinkerService:
content.linker_version += 1
content.save(update_fields=['html_content', 'internal_links', 'linker_version'])
# Deduct credits
# Deduct credits (non-AI operation - use fixed token estimate)
# Estimate: 1 token per 4 characters of HTML content
estimated_tokens = len(content.html_content or '') // 4
self.credit_service.deduct_credits_for_operation(
account=account,
operation_type='linking',
tokens_input=estimated_tokens,
tokens_output=0, # No output tokens for linking operation
description=f"Internal linking for content: {content.title or 'Untitled'}",
related_object_type='content',
related_object_id=content.id
@@ -139,10 +143,14 @@ class LinkerService:
content.linker_version += 1
content.save(update_fields=['html_content', 'internal_links', 'linker_version'])
# Deduct credits
# Deduct credits (non-AI operation - use fixed token estimate)
# Estimate: 1 token per 4 characters of HTML content
estimated_tokens = len(content.html_content or '') // 4
self.credit_service.deduct_credits_for_operation(
account=account,
operation_type='linking',
tokens_input=estimated_tokens,
tokens_output=0,
description=f"Product linking for: {content.title or 'Untitled'}",
related_object_type='content',
related_object_id=content.id
@@ -193,10 +201,14 @@ class LinkerService:
content.linker_version += 1
content.save(update_fields=['html_content', 'internal_links', 'linker_version'])
# Deduct credits
# Deduct credits (non-AI operation - use fixed token estimate)
# Estimate: 1 token per 4 characters of HTML content
estimated_tokens = len(content.html_content or '') // 4
self.credit_service.deduct_credits_for_operation(
account=account,
operation_type='linking',
tokens_input=estimated_tokens,
tokens_output=0,
description=f"Taxonomy linking for: {content.title or 'Untitled'}",
related_object_type='content',
related_object_id=content.id