refactor: Fix AI billing system - revert to commit #10 + fixes

- Reverted to commit #10 (98e68f6) for stable AI function base
- Fixed database migrations: removed 0018-0019 that broke schema
- Fixed CreditCostConfig schema: restored credits_cost, unit fields
- Fixed historical table schema for django-simple-history
- Added debug system (staged for future use)

Changes:
- CreditCostConfig: Updated OPERATION_TYPE_CHOICES (10 ops, no duplicates)
- CreditUsageLog: Updated choices with legacy aliases marked
- Migration 0018_update_operation_choices: Applied successfully
- All AI operations working (clustering, ideas, content, optimization, etc.)

Test Results:
✓ CreditCostConfig save/load working
✓ Credit check passing for all operations
✓ AICore initialization successful
✓ AIEngine operation mapping functional
✓ Admin panel accessible without 500 errors

Future: AI-MODEL-COST-REFACTOR-PLAN.md created for token-based system
This commit is contained in:
IGNY8 VPS (Salman)
2025-12-23 05:21:52 +00:00
parent 98e68f6bd8
commit 1d4825ad77
14 changed files with 1279 additions and 4 deletions

View File

@@ -75,10 +75,16 @@ class CreditUsageLog(AccountBaseModel):
('idea_generation', 'Content Ideas Generation'),
('content_generation', 'Content Generation'),
('image_generation', 'Image Generation'),
('image_prompt_extraction', 'Image Prompt Extraction'),
('linking', 'Internal Linking'),
('optimization', 'Content Optimization'),
('reparse', 'Content Reparse'),
('ideas', 'Content Ideas Generation'), # Legacy
('content', 'Content Generation'), # Legacy
('images', 'Image Generation'), # Legacy
('site_structure_generation', 'Site Structure Generation'),
('site_page_generation', 'Site Page Generation'),
# Legacy aliases for backward compatibility (don't show in new dropdowns)
('ideas', 'Content Ideas Generation (Legacy)'),
('content', 'Content Generation (Legacy)'),
('images', 'Image Generation (Legacy)'),
]
operation_type = models.CharField(max_length=50, choices=OPERATION_TYPE_CHOICES, db_index=True)
@@ -112,11 +118,26 @@ class CreditCostConfig(models.Model):
Configurable credit costs per AI function
Admin-editable alternative to hardcoded constants
"""
# Active operation types (excludes legacy aliases)
OPERATION_TYPE_CHOICES = [
('clustering', 'Keyword Clustering'),
('idea_generation', 'Content Ideas Generation'),
('content_generation', 'Content Generation'),
('image_generation', 'Image Generation'),
('image_prompt_extraction', 'Image Prompt Extraction'),
('linking', 'Internal Linking'),
('optimization', 'Content Optimization'),
('reparse', 'Content Reparse'),
('site_structure_generation', 'Site Structure Generation'),
('site_page_generation', 'Site Page Generation'),
]
# Operation identification
operation_type = models.CharField(
max_length=50,
unique=True,
choices=CreditUsageLog.OPERATION_TYPE_CHOICES,
choices=OPERATION_TYPE_CHOICES,
help_text="AI operation type"
)