299 lines
12 KiB
Python
299 lines
12 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test AI with LARGE INPUT (5000+ tokens) and LARGE OUTPUT (5000+ tokens)
|
|
This simulates real content generation scenarios
|
|
"""
|
|
import os, sys, django
|
|
sys.path.insert(0, '/app')
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings')
|
|
django.setup()
|
|
|
|
import requests
|
|
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')
|
|
|
|
print(f"🧪 Testing {model} with LARGE INPUT + LARGE OUTPUT")
|
|
print("=" * 80)
|
|
print()
|
|
|
|
# Create a VERY LONG prompt to ensure input > 5000 tokens
|
|
# Including detailed outline, examples, and extensive instructions
|
|
large_prompt = """You are a professional content writer. Generate a complete, comprehensive article following this detailed specification.
|
|
|
|
## Article Topic: "Complete Guide to Organic Cotton Bedding: Benefits, Types, and Buying Guide"
|
|
|
|
## Target Word Count: 2500+ words (approximately 3500+ tokens in output)
|
|
|
|
## JSON Output Format Required:
|
|
{
|
|
"title": "article title",
|
|
"meta_title": "SEO title under 60 chars",
|
|
"meta_description": "SEO description under 160 chars",
|
|
"content": "<full HTML content>",
|
|
"word_count": actual_word_count,
|
|
"primary_keyword": "organic cotton bedding",
|
|
"secondary_keywords": ["eco-friendly bedding", "sustainable sheets", "organic duvet covers"],
|
|
"tags": ["organic bedding", "sustainable home", "eco-friendly textiles", "cotton sheets", "bedroom essentials"],
|
|
"categories": ["Home & Living > Bedding", "Sustainable Living > Eco-Friendly Products"]
|
|
}
|
|
|
|
## DETAILED CONTENT STRUCTURE (Each section must be fully written with examples, data, and depth):
|
|
|
|
### Section 1: Introduction (300 words)
|
|
Write a compelling introduction that:
|
|
- Opens with an engaging hook about the rise of organic bedding
|
|
- Explains why consumers are switching from conventional to organic cotton
|
|
- Discusses market trends and growth statistics
|
|
- Mentions health concerns with conventional bedding
|
|
- Previews what readers will learn in this comprehensive guide
|
|
- Naturally incorporates the primary keyword "organic cotton bedding"
|
|
|
|
### Section 2: Understanding Organic Cotton (400 words)
|
|
Write a detailed section covering:
|
|
- Definition of organic cotton and GOTS (Global Organic Textile Standard) certification
|
|
- Differences between organic and conventional cotton farming practices
|
|
- Specific pesticides and chemicals avoided in organic farming
|
|
- Water usage statistics (organic vs conventional)
|
|
- Soil health and crop rotation practices
|
|
- Carbon footprint comparison data
|
|
- Other certifications to look for (OEKO-TEX, Fair Trade, etc.)
|
|
- Include specific examples of organic cotton farms and their practices
|
|
- Mention leading organic cotton producing regions globally
|
|
|
|
### Section 3: Health Benefits of Organic Cotton Bedding (400 words)
|
|
Comprehensive coverage of:
|
|
- Hypoallergenic properties and why they matter
|
|
- Impact on sensitive skin and skin conditions (eczema, psoriasis, allergies)
|
|
- Chemical residues in conventional bedding and health risks
|
|
- Dermatologist recommendations and clinical studies
|
|
- Respiratory benefits from chemical-free textiles
|
|
- Benefits for babies and children
|
|
- Real customer testimonials and experiences
|
|
- Comparison of skin irritation rates between organic and conventional bedding
|
|
- Long-term health advantages
|
|
|
|
### Section 4: Environmental Impact and Sustainability (400 words)
|
|
Detailed analysis including:
|
|
- Water conservation statistics (gallons saved per pound of cotton)
|
|
- Pesticide elimination impact on ecosystems
|
|
- Biodiversity benefits for pollinators and wildlife
|
|
- Soil degradation prevention through organic farming
|
|
- Carbon emissions comparison with conventional cotton
|
|
- Impact on farmer health and community welfare
|
|
- Waste reduction in textile production
|
|
- End-of-life biodegradability
|
|
- Circular economy considerations
|
|
- Case studies of sustainable bedding brands
|
|
|
|
### Section 5: Types of Organic Cotton Bedding (350 words)
|
|
Comprehensive overview of:
|
|
- Organic cotton sheets (fitted, flat, pillowcases)
|
|
- Thread count ranges and what they mean
|
|
- Weave types: percale, sateen, jersey, flannel
|
|
- Specific characteristics of each weave
|
|
- Organic cotton duvet covers and comforters
|
|
- Fill power and warmth ratings
|
|
- Seasonal considerations
|
|
- Organic cotton mattress protectors and pads
|
|
- Waterproof vs breathable options
|
|
- Organic cotton blankets and throws
|
|
- Specialty items (body pillows, Euro shams, bed skirts)
|
|
- Price ranges for each category
|
|
- Brand examples for each product type
|
|
|
|
### Section 6: Quality Factors and What to Look For (350 words)
|
|
In-depth buying guidance:
|
|
- Thread count myths and realities (why 800+ isn't always better)
|
|
- Ply differences (single-ply vs multi-ply)
|
|
- Weave construction details
|
|
- Fabric weight and GSM (grams per square meter)
|
|
- Fiber length and quality grades
|
|
- Color fastness and dye methods (low-impact dyes)
|
|
- Shrinkage rates and pre-washing
|
|
- Durability testing standards
|
|
- Pilling resistance
|
|
- How to verify authentic organic certification
|
|
- Red flags for fake "organic" claims
|
|
|
|
### Section 7: Top Organic Cotton Bedding Brands (400 words)
|
|
Detailed brand reviews including:
|
|
- Coyuchi: Product range, price points, unique features, customer ratings
|
|
- Boll & Branch: Signature products, fair trade practices, pricing
|
|
- Parachute: Material quality, design aesthetic, value proposition
|
|
- Pottery Barn Organic: Accessibility, variety, retail presence
|
|
- West Elm Organic: Style options, price range, sustainability initiatives
|
|
- SOL Organics: Budget-friendly options, certification details
|
|
- Avocado: Premium positioning, additional eco-features
|
|
- Include specific product examples from each brand
|
|
- Price comparison table format
|
|
- Warranty and return policy highlights
|
|
|
|
### Section 8: Care and Maintenance (300 words)
|
|
Comprehensive care instructions:
|
|
- Initial washing recommendations before first use
|
|
- Water temperature guidelines for different weaves
|
|
- Detergent recommendations (eco-friendly, fragrance-free)
|
|
- Drying methods: air-dry vs machine dry
|
|
- Ironing tips for different weaves
|
|
- Stain removal techniques for organic cotton
|
|
- Frequency of washing for longevity
|
|
- Storage recommendations for seasonal items
|
|
- How to maintain whiteness without bleach
|
|
- Expected lifespan with proper care (5-10 years)
|
|
- When to replace bedding
|
|
|
|
### Section 9: Cost Analysis and Value Proposition (300 words)
|
|
Financial breakdown:
|
|
- Price range overview: budget ($50-100), mid-range ($100-250), premium ($250-500+)
|
|
- Cost per use calculation over 5 years
|
|
- Durability comparison with conventional bedding
|
|
- Health cost savings (reduced allergies, better sleep)
|
|
- Environmental value beyond personal use
|
|
- Sale and discount timing (when to buy)
|
|
- Starter set recommendations for budget-conscious buyers
|
|
- Investment prioritization (which pieces to buy first)
|
|
- Comparison with luxury conventional bedding prices
|
|
|
|
### Section 10: Where to Buy (200 words)
|
|
Shopping guide including:
|
|
- Direct-to-consumer brands (online)
|
|
- Major retailers (Pottery Barn, West Elm, Crate & Barrel)
|
|
- Amazon and online marketplaces (verification tips)
|
|
- Local organic stores and boutiques
|
|
- Outlet and discount sources
|
|
- International shipping considerations
|
|
- Return policies and trial periods
|
|
- Customer service quality comparisons
|
|
|
|
### Section 11: Conclusion (150 words)
|
|
Wrap up with:
|
|
- Summary of key benefits
|
|
- Final recommendations for different buyer types
|
|
- Call to action
|
|
- Future of organic bedding industry
|
|
|
|
## Writing Requirements:
|
|
- Use active voice throughout
|
|
- Include specific data points, statistics, and examples
|
|
- Vary sentence structure for natural flow
|
|
- Use HTML tags properly: <p>, <h2>, <h3>, <ul>, <ol>, <table>
|
|
- Create comparison tables where appropriate
|
|
- Use <blockquote> for expert quotes or key insights
|
|
- Maintain professional, editorial tone
|
|
- Avoid generic phrases and filler content
|
|
- Each paragraph should be 3-5 sentences minimum
|
|
- Lists should have detailed descriptions, not just bullet points
|
|
|
|
Return ONLY the JSON object. The content field must contain ALL sections fully written in HTML format."""
|
|
|
|
print("📊 Prompt Statistics:")
|
|
print(f" Prompt Length: {len(large_prompt)} characters")
|
|
print(f" Estimated Input Tokens: ~{len(large_prompt) // 4} tokens")
|
|
print()
|
|
|
|
# Test with different max_tokens settings
|
|
tests = [
|
|
{"name": "Test 1: max_tokens=4096", "max_tokens": 4096},
|
|
{"name": "Test 2: max_tokens=8192", "max_tokens": 8192},
|
|
{"name": "Test 3: max_tokens=16384", "max_tokens": 16384},
|
|
]
|
|
|
|
print("🚀 Starting API Tests...")
|
|
print("=" * 80)
|
|
|
|
for test in tests:
|
|
print(f"\n{test['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': large_prompt}],
|
|
'max_tokens': test['max_tokens'],
|
|
'temperature': 0.7,
|
|
},
|
|
timeout=180 # 3 minutes for long generation
|
|
)
|
|
|
|
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)
|
|
|
|
# Estimate word count (1 token ≈ 0.75 words)
|
|
estimated_words = int(completion_tokens * 0.75)
|
|
|
|
print(f"✓ Response received")
|
|
print(f" Input Tokens: {prompt_tokens:>6,} tokens")
|
|
print(f" Output Tokens: {completion_tokens:>6,} tokens")
|
|
print(f" Total Tokens: {total_tokens:>6,} tokens")
|
|
print(f" Estimated Words: ~{estimated_words:>5,} words")
|
|
print(f" Finish Reason: {finish_reason}")
|
|
|
|
if finish_reason == 'length':
|
|
print(f" 🚨 TRUNCATED: Hit max_tokens={test['max_tokens']:,} limit!")
|
|
print(f" ⚠️ Content is INCOMPLETE - needs higher max_tokens")
|
|
elif finish_reason == 'stop':
|
|
print(f" ✅ COMPLETE: Response finished naturally")
|
|
|
|
# Check if we met our goals
|
|
if prompt_tokens > 5000:
|
|
print(f" ✅ Input > 5000 tokens")
|
|
else:
|
|
print(f" ⚠️ Input only {prompt_tokens} tokens (target: 5000+)")
|
|
|
|
if completion_tokens > 5000:
|
|
print(f" ✅ Output > 5000 tokens")
|
|
else:
|
|
print(f" ⚠️ Output only {completion_tokens} tokens (target: 5000+)")
|
|
|
|
else:
|
|
error_data = response.json()
|
|
error_msg = error_data.get('error', {}).get('message', 'Unknown error')
|
|
print(f" ✗ API Error: {response.status_code}")
|
|
print(f" Error: {error_msg}")
|
|
|
|
except requests.exceptions.Timeout:
|
|
print(f" ✗ Request timed out after 180 seconds")
|
|
except Exception as e:
|
|
print(f" ✗ Exception: {str(e)}")
|
|
|
|
print("\n" + "=" * 80)
|
|
print("🎯 FINAL ANALYSIS")
|
|
print("=" * 80)
|
|
print()
|
|
print("Key Questions Answered:")
|
|
print()
|
|
print("1. Can the model handle 5000+ token INPUT?")
|
|
print(" → Check 'Input Tokens' above (should be 5000+)")
|
|
print()
|
|
print("2. Can the model generate 5000+ token OUTPUT?")
|
|
print(" → Check 'Output Tokens' above (should be 5000+)")
|
|
print()
|
|
print("3. Does max_tokens limit actually work as expected?")
|
|
print(" → Compare output tokens across tests with different limits")
|
|
print()
|
|
print("4. Is content getting truncated with current 8192 setting?")
|
|
print(" → Check if 'Finish Reason' is 'length' for 8192 test")
|
|
print()
|
|
print("💡 RECOMMENDATION:")
|
|
print(" If Test 2 (8192) shows 'TRUNCATED', increase max_tokens for content generation")
|
|
print(" If Test 3 (16384) shows 'COMPLETE', that's the minimum needed for long articles")
|
|
print()
|