iamge genration credits fixing - not fixed

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-10 09:39:17 +00:00
parent 60f981cafd
commit 622e66b0fb
5 changed files with 307 additions and 14 deletions

View File

@@ -9,6 +9,7 @@
| Version | Date | Summary |
|---------|------|---------|
| 1.7.1 | Jan 10, 2026 | **Image Generation Credits** - Complete credit deduction, verification, and logging for all image generation models (DALL-E 3, Runware, Google); Pre-generation credit check; AITaskLog logging; Notification integration |
| 1.7.0 | Jan 10, 2026 | **Major** - Pre-Launch Cleanup Complete (Phases 1, 5, 6): Code cleanup, UX improvements, data backup tools; WordPress plugin distribution system; Template design improvements; AI model fixes |
| 1.6.2 | Jan 8, 2026 | **Design Refinements** - Updated marketing site gradients to brand colors (primary + success), reduced shadow weights, simplified automation icons, added Upcoming Features page |
| 1.6.1 | Jan 8, 2026 | **Email System** - SMTP configuration, email templates, password reset flow, email verification, unsubscribe functionality |
@@ -40,6 +41,83 @@
---
## v1.7.1 - January 10, 2026
### Image Generation Credit System
This release implements complete credit deduction, verification, and logging for all 3 image generation models, ensuring consistency with other AI functions in the automation pipeline.
---
### 💰 Credit System for Image Generation
**New Credit Check Method:**
- Added `CreditService.check_credits_for_image()` in [credit_service.py:307-335](backend/igny8_core/business/billing/services/credit_service.py#L307-L335)
- Pre-checks if account has sufficient credits before image generation starts
- Uses `credits_per_image` from AIModelConfig (as configured in admin)
- Returns required credits or raises `InsufficientCreditsError`
**Pre-Generation Credit Verification:**
- Added credit check before processing images in [tasks.py:290-319](backend/igny8_core/ai/tasks.py#L290-L319)
- Checks total credits needed for all images BEFORE starting generation
- Returns error with `InsufficientCreditsError` if not enough credits
- Gracefully handles missing model configurations for backward compatibility
**Credit Deduction (Already Existed - Now Verified):**
- `deduct_credits_for_image()` called after each successful image in [tasks.py:745-770](backend/igny8_core/ai/tasks.py#L745-L770)
- Fixed cost retrieval to use `result.get('cost')` (was incorrectly using `cost_usd`)
- Credits per model (from AIModelConfig):
- `runware:97@1`: 1 credit/image (basic tier)
- `dall-e-3`: 5 credits/image (quality tier)
- `google:4@2`: 15 credits/image (premium tier)
---
### 📊 Logging & Notifications
**AITaskLog Integration:**
- Added AITaskLog logging in [tasks.py:838-875](backend/igny8_core/ai/tasks.py#L838-L875)
- Records function_name (`generate_images`), account, phase, status, cost
- Consistent with other AI function logging (clustering, content generation, etc.)
**Notification Integration:**
- Added notification creation in [tasks.py:877-895](backend/igny8_core/ai/tasks.py#L877-L895)
- Creates success notifications via `NotificationService.notify_images_complete()`
- Creates failure notifications via `NotificationService.notify_images_failed()`
- Same pattern as used in AIEngine for other AI functions
---
### 🔄 Automation Compatibility
**Verified automation flow for image generation:**
- Stage 6 in automation service calls `process_image_generation_queue` correctly
- Credit deduction happens inside the task (same as manual image generation)
- Credits tracked via `_get_credits_used()` and stored in `stage_6_result`
- Consistent with Stages 1, 2, 4, 5 credit tracking
---
### 📁 Files Changed
| File | Changes |
|------|---------|
| `backend/igny8_core/business/billing/services/credit_service.py` | Added `check_credits_for_image()` method |
| `backend/igny8_core/ai/tasks.py` | Added credit check, AITaskLog logging, notifications |
---
### 📋 Credit Usage Logging Locations
| Table | Purpose |
|-------|---------|
| `CreditTransaction` | Financial ledger entry (via `deduct_credits_for_image`) |
| `CreditUsageLog` | Detailed usage log with model, cost, credits |
| `AITaskLog` | AI task execution tracking |
| `Notification` | User notifications for completion/failure |
---
## v1.7.0 - January 10, 2026
### Pre-Launch Cleanup & Plugin Distribution System