#!/usr/bin/env python """ Test with ACTUAL content generation prompt structure to see real token usage """ import os, sys, django sys.path.insert(0, '/app') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings') django.setup() import requests, json from igny8_core.modules.system.models import IntegrationSettings from igny8_core.auth.models import Account account = Account.objects.filter(slug='aws-admin').first() settings = IntegrationSettings.objects.filter(integration_type='openai', account=account, is_active=True).first() config = settings.config or {} api_key = config.get('apiKey') model = config.get('model', 'gpt-4o') # Read the ACTUAL content generation prompt with open('/data/content-generation-prompt.md', 'r') as f: prompt_template = f.read() # Create realistic content idea with 7 detailed H2 sections idea_data = { "title": "Complete Guide to Organic Cotton Bedding: Benefits, Care, and Buying Tips", "description": { "introduction": { "hook": "Transform your bedroom into a healthier sanctuary with organic cotton bedding that promises better sleep and peace of mind.", "paragraphs": [ {"content_type": "paragraph", "details": "Growing consumer awareness of chemical exposure in everyday products | Rise of organic bedding market | Health and environmental benefits driving adoption"}, {"content_type": "paragraph", "details": "Investment in quality sleep surfaces | Long-term value proposition | This comprehensive guide covers everything you need to know"} ] }, "H2": [ {"heading": "Understanding Organic Cotton Certification", "subsections": [ {"subheading": "GOTS Standards Explained", "content_type": "paragraph", "details": "Global Organic Textile Standard requirements | Certification process | Third-party verification"}, {"subheading": "Other Important Certifications", "content_type": "list", "details": "OEKO-TEX Standard 100 | Fair Trade | Organic Content Standard"}, {"subheading": "Verification Methods", "content_type": "paragraph", "details": "How to verify authentic certifications | Common red flags | Label reading guide"} ]}, {"heading": "Health Benefits of Organic Cotton Bedding", "subsections": [ {"subheading": "Hypoallergenic Properties", "content_type": "paragraph", "details": "Absence of chemical irritants | Benefits for sensitive skin | Clinical studies on allergen reduction"}, {"subheading": "Chemical-Free Advantages", "content_type": "paragraph", "details": "Pesticide residues in conventional cotton | Health impacts of formaldehyde and other chemicals | Dermatologist recommendations"}, {"subheading": "Impact on Sleep Quality", "content_type": "paragraph", "details": "Breathability and temperature regulation | Moisture wicking properties | Sleep study findings"} ]}, {"heading": "Environmental Impact and Sustainability", "subsections": [ {"subheading": "Water Conservation", "content_type": "paragraph", "details": "Water usage comparison organic vs conventional | Statistics on water savings | Impact on global water resources"}, {"subheading": "Pesticide Elimination", "content_type": "list", "details": "Toxic chemicals avoided | Impact on ecosystems | Soil health benefits"}, {"subheading": "Carbon Footprint", "content_type": "table", "details": "Emissions comparison | Manufacturing process differences | Transportation considerations"} ]}, {"heading": "Quality Factors and Thread Count", "subsections": [ {"subheading": "Thread Count Myths", "content_type": "paragraph", "details": "Why higher isn't always better | Optimal thread count ranges | Marketing misconceptions"}, {"subheading": "Weave Types Compared", "content_type": "table", "details": "Percale characteristics | Sateen properties | Jersey and flannel options | Best use cases for each"}, {"subheading": "Durability Factors", "content_type": "paragraph", "details": "Fiber length and strength | Ply construction | Expected lifespan with proper care"} ]}, {"heading": "Top Organic Cotton Bedding Brands", "subsections": [ {"subheading": "Premium Brands", "content_type": "paragraph", "details": "Coyuchi overview and price range | Boll & Branch unique features | Parachute product line"}, {"subheading": "Mid-Range Options", "content_type": "list", "details": "West Elm Organic collection | Pottery Barn Organic line | Target's organic offerings"}, {"subheading": "Budget-Friendly Choices", "content_type": "paragraph", "details": "SOL Organics value proposition | Amazon organic options | Direct-to-consumer brands"} ]}, {"heading": "Buying Guide and Shopping Tips", "subsections": [ {"subheading": "What to Look For", "content_type": "list", "details": "Certification verification | Return policies | Warranty coverage | Customer reviews"}, {"subheading": "When to Buy", "content_type": "paragraph", "details": "Best sale seasons | Holiday promotions | End-of-season clearances"}, {"subheading": "Starter Set Recommendations", "content_type": "paragraph", "details": "Essential pieces for beginners | Budget allocation | Prioritization strategy"} ]}, {"heading": "Care and Maintenance Best Practices", "subsections": [ {"subheading": "Washing Instructions", "content_type": "paragraph", "details": "Pre-washing requirements | Water temperature guidelines | Eco-friendly detergent recommendations"}, {"subheading": "Drying and Storage", "content_type": "list", "details": "Air-dry vs machine dry | Shrinkage prevention | Long-term storage tips"}, {"subheading": "Longevity Tips", "content_type": "paragraph", "details": "Rotation schedules | Stain removal methods | When to replace"} ]} ] }, "content_type": "post", "content_structure": "guide", "estimated_word_count": 2000 } # Format the prompt with real data prompt = prompt_template.replace('[IGNY8_IDEA]', json.dumps(idea_data, indent=2)) prompt = prompt.replace('[IGNY8_CLUSTER]', 'Organic Bedding') prompt = prompt.replace('[IGNY8_KEYWORDS]', 'organic cotton bedding, eco-friendly sheets, sustainable duvet covers, GOTS certified bedding, hypoallergenic sheets, organic mattress protector, chemical-free bedding, organic cotton pillowcases') print(f"๐Ÿงช Testing with REAL content generation prompt") print("=" * 80) print(f"Prompt characters: {len(prompt):,}") print(f"Estimated input tokens: ~{len(prompt) // 4:,}") print() tests = [ ("max_tokens=4096", 4096), ("max_tokens=8192", 8192), ("max_tokens=16384", 16384), ] for name, max_tokens in tests: print(f"\n๐Ÿ“ {name}") print("-" * 80) try: response = requests.post( 'https://api.openai.com/v1/chat/completions', headers={'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json'}, json={ 'model': model, 'messages': [{'role': 'user', 'content': prompt}], 'max_tokens': max_tokens, 'temperature': 0.7, 'response_format': {"type": "json_object"} # JSON mode like real requests }, timeout=180 ) if response.status_code == 200: data = response.json() usage = data.get('usage', {}) finish_reason = data['choices'][0].get('finish_reason') prompt_tokens = usage.get('prompt_tokens', 0) completion_tokens = usage.get('completion_tokens', 0) total_tokens = usage.get('total_tokens', 0) estimated_words = int(completion_tokens * 0.75) print(f" Input: {prompt_tokens:>6,} tokens") print(f" Output: {completion_tokens:>6,} tokens (~{estimated_words:,} words)") print(f" Total: {total_tokens:>6,} tokens") print(f" Status: {finish_reason}") if finish_reason == 'length': print(f" ๐Ÿšจ TRUNCATED - Content incomplete!") else: print(f" โœ… Complete response") else: print(f" โœ— Error: {response.status_code}") print(f" {response.json().get('error', {}).get('message', '')[:100]}") except Exception as e: print(f" โœ— Exception: {str(e)[:100]}") print("\n" + "=" * 80) print("๐ŸŽฏ CONCLUSION") print("=" * 80) print("Check which max_tokens setting allows complete 1200+ word articles") print("If 8192 shows 'TRUNCATED', we need to increase it in settings.py")