104 lines
3.0 KiB
Python
104 lines
3.0 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test ACTUAL content generation using existing task (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.functions.generate_content import execute as generate_content
|
|
from igny8_core.auth.models import Account
|
|
from igny8_core.business.content.models import Tasks, Content
|
|
import re
|
|
from html import unescape
|
|
|
|
print("=" * 80)
|
|
print("TESTING ACTUAL CONTENT GENERATION (same function as frontend)")
|
|
print("=" * 80)
|
|
print()
|
|
|
|
# Get account and task
|
|
account = Account.objects.filter(slug='aws-admin').first()
|
|
task_id = 229 # "Essential Garden Tools for Every Gardener"
|
|
|
|
task = Tasks.objects.get(id=task_id)
|
|
print(f"✅ Using task: {task.title}")
|
|
print()
|
|
|
|
# Delete any existing content for this task to start fresh
|
|
existing = Content.objects.filter(task=task)
|
|
if existing.exists():
|
|
count = existing.count()
|
|
existing.delete()
|
|
print(f"🗑️ Deleted {count} existing content items")
|
|
print()
|
|
|
|
print("=" * 80)
|
|
print("CALLING generate_content() - THE ACTUAL FUNCTION")
|
|
print("=" * 80)
|
|
print()
|
|
|
|
# Call the ACTUAL function
|
|
try:
|
|
result = generate_content(
|
|
payload={'ids': [task_id]},
|
|
account=account,
|
|
user=None
|
|
)
|
|
|
|
print()
|
|
print("=" * 80)
|
|
print("GENERATION RESULT")
|
|
print("=" * 80)
|
|
print()
|
|
|
|
if result.get('success'):
|
|
print(f"✅ Success: {result.get('message')}")
|
|
print(f" Items: {result.get('count', 0)}")
|
|
print()
|
|
|
|
# Get the generated content
|
|
content = Content.objects.filter(task=task).order_by('-created_at').first()
|
|
|
|
if content:
|
|
# Count actual words
|
|
html_content = content.content_html or ''
|
|
text_only = re.sub(r'<[^>]+>', '', html_content)
|
|
text_only = unescape(text_only)
|
|
words = len(text_only.split())
|
|
|
|
print(f"📝 Content Details:")
|
|
print(f" Title: {content.title}")
|
|
print(f" Word Count (actual): {words}")
|
|
print(f" Word Count (reported): {content.word_count}")
|
|
print()
|
|
|
|
if words < 1200:
|
|
print(f"🚨 CRITICAL ISSUE: Only {words} words!")
|
|
print(f" Target: 1200+ words")
|
|
print(f" Shortfall: {1200 - words} words")
|
|
else:
|
|
print(f"✅ EXCELLENT: {words} words (exceeds 1200)")
|
|
|
|
print()
|
|
print("=" * 80)
|
|
print("FIRST 800 CHARACTERS OF CONTENT:")
|
|
print("=" * 80)
|
|
print(text_only[:800])
|
|
print()
|
|
print(f"[...{len(text_only) - 800} more characters...]" if len(text_only) > 800 else "")
|
|
|
|
else:
|
|
print(f"❌ Failed: {result.get('error')}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Exception: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
print()
|
|
print("=" * 80)
|
|
print("This is the EXACT same generate_content() function called by frontend")
|
|
print("=" * 80)
|