#!/usr/bin/env python """ Test the ACTUAL AI function execution path (same as frontend) """ import os, sys, django sys.path.insert(0, '/app') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings') django.setup() from igny8_core.ai.tasks import run_ai_task from igny8_core.auth.models import Account, Site from igny8_core.business.content.models import Tasks import json # Get account account = Account.objects.filter(slug='aws-admin').first() site = Site.objects.filter(account=account).first() # Create a test task with the massager content idea task_data = { "title": "Top Shiatsu Back and Neck Massagers for Effective Pain Relief", "description": json.dumps({ "introduction": { "hook": "Explore the best shiatsu back and neck massagers to alleviate pain and improve relaxation.", "paragraphs": [ {"content_type": "paragraph", "details": "Introduction to the concept of shiatsu massage and its effectiveness for pain relief."}, {"content_type": "paragraph", "details": "The shift towards home-based massage solutions in managing chronic pain."} ] }, "H2": [ { "heading": "Understanding Shiatsu Back and Neck Massagers", "subsections": [ {"subheading": "The Science of Shiatsu Massage", "content_type": "paragraph", "details": "Explanation of shiatsu techniques and their therapeutic benefits."}, {"subheading": "Choosing the Right Shiatsu Massager", "content_type": "list", "details": "Evaluating features like heat, intensity settings, and portability."} ] }, { "heading": "Benefits of Shiatsu Massagers for Neck and Back", "subsections": [ {"subheading": "Pain Relief and Muscle Relaxation", "content_type": "paragraph", "details": "How shiatsu massage helps release muscle tension."}, {"subheading": "Improved Sleep and Stress Reduction", "content_type": "list", "details": "Additional health benefits of regular shiatsu massages."} ] }, { "heading": "Top Shiatsu Back and Neck Massagers to Consider", "subsections": [ {"subheading": "High-End Models", "content_type": "paragraph", "details": "Features of top-tier shiatsu massagers."}, {"subheading": "Best Budget Picks", "content_type": "list", "details": "Affordable options without compromising on quality."} ] }, { "heading": "User Guide: How to Use a Shiatsu Massager", "subsections": [ {"subheading": "Step-by-Step Instructions", "content_type": "paragraph", "details": "Detailed guide on using your massager effectively."}, {"subheading": "Safety Tips", "content_type": "list", "details": "Precautions to ensure safe and beneficial use."} ] }, { "heading": "Comparing Shiatsu and Electric Massagers for Back Pain", "subsections": [ {"subheading": "Pros and Cons", "content_type": "paragraph", "details": "Comparison of features and benefits."}, {"subheading": "Choosing Based on Personal Needs", "content_type": "list", "details": "Factors to consider when selecting a massager."} ] }, { "heading": "Caring for Your Shiatsu Massager", "subsections": [ {"subheading": "Cleaning and Maintenance Tips", "content_type": "paragraph", "details": "Ensuring your massager lasts longer with proper care."}, {"subheading": "Troubleshooting and Repairs", "content_type": "list", "details": "Common issues and how to fix them."} ] } ] }), "content_type": "post", "content_structure": "comparison", "keywords": "shiatsu back and neck massager, shiatsu neck and back massager, shiatsu back massager", "status": "new", "account": account, "site": site, } # Create or get existing test task task = Tasks.objects.filter( title=task_data['title'], account=account ).first() if not task: task = Tasks.objects.create(**task_data) print(f"✅ Created test task: {task.id}") else: print(f"✅ Using existing task: {task.id}") print() print("=" * 70) print("RUNNING ACTUAL AI FUNCTION (same path as frontend)") print("=" * 70) print() # Run the ACTUAL function (synchronous, not Celery) result = run_ai_task( function_name='generate_content', payload={'ids': [task.id]}, account_id=account.id, self=type('obj', (object,), {'request': type('obj', (object,), {'id': 'test-task-id'})(), 'update_state': lambda *args, **kwargs: None})() ) print() print("=" * 70) print("RESULT") print("=" * 70) print() if result.get('success'): print("✅ Content generated successfully") print(f" Items created: {result.get('count', 0)}") # Get the generated content from igny8_core.business.content.models import Content content = Content.objects.filter(task=task).order_by('-created_at').first() if content: # Count actual words import re from html import unescape html_content = content.content_html or '' # Strip HTML tags text_only = re.sub(r'<[^>]+>', '', html_content) # Unescape HTML entities text_only = unescape(text_only) # Count words words = len(text_only.split()) print(f" Title: {content.title[:60]}...") print(f" Word Count (actual): {words}") print(f" Word Count (reported): {content.word_count}") print() if words < 1200: print(f"🚨 PROBLEM: Only {words} words generated (target: 1200+)") print(f" Shortfall: {1200 - words} words missing") else: print(f"✅ SUCCESS: {words} words generated (exceeds 1200 minimum)") # Show first 500 chars print() print("First 500 characters of content:") print("-" * 70) print(text_only[:500]) else: print(f"❌ Generation failed: {result.get('error')}") print() print("=" * 70) print("This is the EXACT same code path used by the frontend") print("=" * 70)