175 lines
5.9 KiB
Python
175 lines
5.9 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to run inside Docker container to diagnose generate_content issues
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings')
|
|
django.setup()
|
|
|
|
import logging
|
|
from django.contrib.auth import get_user_model
|
|
from igny8_core.auth.models import Account
|
|
from igny8_core.business.site_building.models import PageBlueprint, SiteBlueprint
|
|
from igny8_core.business.site_building.services.page_generation_service import PageGenerationService
|
|
from igny8_core.modules.system.models import IntegrationSettings
|
|
from igny8_core.ai.settings import get_model_config
|
|
|
|
# Set up logging
|
|
logging.basicConfig(
|
|
level=logging.DEBUG,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def main():
|
|
print("=" * 80)
|
|
print("GENERATE_CONTENT DIAGNOSTIC TEST")
|
|
print("=" * 80)
|
|
|
|
# 1. Test User Authentication and get Account
|
|
print("\n1. Testing User Authentication...")
|
|
User = get_user_model()
|
|
user = User.objects.filter(email='dev@igny8.com').first()
|
|
|
|
if not user:
|
|
print("❌ ERROR: User 'dev@igny8.com' not found!")
|
|
return
|
|
|
|
print(f"✓ User found: {user.email} (ID: {user.id})")
|
|
|
|
# Get the associated account
|
|
account = user.account if hasattr(user, 'account') else None
|
|
if not account:
|
|
print("❌ ERROR: User has no associated Account!")
|
|
return
|
|
|
|
print(f"✓ Account found: {account.id}")
|
|
|
|
# 2. Check Integration Settings
|
|
print("\n2. Checking Integration Settings...")
|
|
try:
|
|
integration = IntegrationSettings.objects.filter(account=account, is_active=True).first()
|
|
if integration:
|
|
print(f"✓ Integration found: {integration.integration_type}")
|
|
print(f" - Config keys: {list(integration.config.keys()) if integration.config else 'None'}")
|
|
print(f" - Active: {integration.is_active}")
|
|
else:
|
|
print("❌ WARNING: No active IntegrationSettings found!")
|
|
print(" This will cause AI requests to fail!")
|
|
except Exception as e:
|
|
print(f"❌ ERROR checking integration: {e}")
|
|
|
|
# 3. Test Model Configuration
|
|
print("\n3. Testing Model Configuration...")
|
|
try:
|
|
model_config = get_model_config('generate_page_content', account=account)
|
|
print(f"✓ Model config loaded:")
|
|
print(f" - Model: {model_config.get('model')}")
|
|
print(f" - Max tokens: {model_config.get('max_tokens')}")
|
|
print(f" - Temperature: {model_config.get('temperature')}")
|
|
except Exception as e:
|
|
print(f"❌ ERROR: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
# 4. Check for Site Blueprints
|
|
print("\n4. Checking for Site Blueprints...")
|
|
site_blueprints = SiteBlueprint.objects.filter(account=account)
|
|
print(f" - Found {site_blueprints.count()} site blueprints")
|
|
|
|
if site_blueprints.exists():
|
|
sb = site_blueprints.first()
|
|
print(f" - First blueprint: {sb.name} (ID: {sb.id})")
|
|
print(f" - Pages: {sb.pages.count()}")
|
|
|
|
# 5. Check for Page Blueprints
|
|
print("\n5. Checking for Page Blueprints...")
|
|
pages = PageBlueprint.objects.filter(account=account)
|
|
print(f" - Found {pages.count()} page blueprints")
|
|
|
|
if not pages.exists():
|
|
print("❌ WARNING: No page blueprints found! Creating a test page...")
|
|
|
|
# Create a test site blueprint if needed
|
|
if not site_blueprints.exists():
|
|
from igny8_core.modules.planner.models import Sector
|
|
sector = Sector.objects.filter(account=account).first()
|
|
|
|
if not sector:
|
|
print("❌ ERROR: No sector found for account. Cannot create test blueprint.")
|
|
return
|
|
|
|
sb = SiteBlueprint.objects.create(
|
|
account=account,
|
|
sector=sector,
|
|
name="Test Site Blueprint",
|
|
site_type="business",
|
|
status="draft"
|
|
)
|
|
print(f"✓ Created test site blueprint: {sb.id}")
|
|
else:
|
|
sb = site_blueprints.first()
|
|
|
|
# Create a test page
|
|
page = PageBlueprint.objects.create(
|
|
account=account,
|
|
site_blueprint=sb,
|
|
sector=sb.sector,
|
|
title="Test Home Page",
|
|
slug="home",
|
|
type="home",
|
|
status="draft",
|
|
blocks_json=[
|
|
{
|
|
"type": "hero",
|
|
"heading": "Welcome to Our Test Site",
|
|
"subheading": "This is a test page for content generation"
|
|
},
|
|
{
|
|
"type": "features",
|
|
"heading": "Our Features"
|
|
}
|
|
]
|
|
)
|
|
print(f"✓ Created test page blueprint: {page.id}")
|
|
else:
|
|
page = pages.first()
|
|
print(f" - Using existing page: {page.title} (ID: {page.id})")
|
|
|
|
# 6. Test generate_page_content
|
|
print("\n6. Testing generate_page_content...")
|
|
print(f" - Page ID: {page.id}")
|
|
print(f" - Page title: {page.title}")
|
|
print(f" - Page type: {page.type}")
|
|
print(f" - Page status: {page.status}")
|
|
print(f" - Blocks count: {len(page.blocks_json) if page.blocks_json else 0}")
|
|
|
|
try:
|
|
service = PageGenerationService()
|
|
print("\n Calling service.generate_page_content()...")
|
|
result = service.generate_page_content(page, force_regenerate=False)
|
|
|
|
print(f"\n✓ SUCCESS!")
|
|
print(f" Result: {result}")
|
|
|
|
except ValueError as e:
|
|
print(f"\n❌ ValueError: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
except Exception as e:
|
|
print(f"\n❌ Exception: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
print("\n" + "=" * 80)
|
|
print("TEST COMPLETE")
|
|
print("=" * 80)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|