#!/usr/bin/env python """ Test if AI can generate 2000+ word content (requires ~2700+ tokens) """ 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 VERY LONG content requirement") print("=" * 70) # This prompt REQUIRES a very long response with many detailed sections prompt = """Generate a complete JSON article about "Complete Guide to Organic Cotton Bedding" following this EXACT structure. Each section MUST be fully detailed with examples, data, and comprehensive explanations. JSON Format: { "title": "Complete Guide to Organic Cotton Bedding: Benefits, Buying Tips, and Care", "content": "", "word_count": 2000 } Content Requirements (MINIMUM 2000 words total):

Introduction

Write 200 words introducing organic cotton bedding, market trends, and why consumers are switching.

What is Organic Cotton?

Write 250 words explaining organic cotton certification, farming methods, GOTS standards, and differences from conventional cotton. Include specific examples of organic farming practices.

Health and Skin Benefits

Write 300 words covering hypoallergenic properties, chemical-free benefits, impact on sensitive skin, dermatologist recommendations, and real-world testimonials.

Environmental Impact and Sustainability

Write 300 words with detailed statistics on water conservation, pesticide elimination, carbon footprint, soil health, biodiversity benefits, and certification bodies.

Quality, Durability, and Thread Count

Write 250 words explaining thread count myths, weave types (percale vs sateen), durability testing, washing cycle performance, and longevity comparisons.

Cost Analysis and Value

Write 250 words with price comparisons, cost-per-use calculations, 5-year ownership analysis, warranty information, and investment justification.

Top Organic Cotton Bedding Brands

Write 250 words reviewing 5-7 major brands with specific product examples, price ranges, unique features, and customer ratings.

Buying Guide and What to Look For

Write 200 words on certification verification, red flags, shopping tips, online vs retail, and return policies. Return ONLY valid JSON. The content field must contain complete HTML with ALL sections fully written.""" tests = [ ("4096 tokens", 4096), ("8192 tokens", 8192), ("16384 tokens", 16384), ] print() for name, max_tokens in tests: print(f"๐Ÿ“ Testing with max_tokens = {max_tokens}") print("-" * 70) 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, }, timeout=120 ) if response.status_code == 200: data = response.json() usage = data.get('usage', {}) finish_reason = data['choices'][0].get('finish_reason') completion = usage.get('completion_tokens', 0) # Rough word count estimate (1 token โ‰ˆ 0.75 words) estimated_words = int(completion * 0.75) print(f" Completion Tokens: {completion}") print(f" Estimated Words: ~{estimated_words}") print(f" Finish Reason: {finish_reason}") if finish_reason == 'length': print(f" โš ๏ธ TRUNCATED at {max_tokens} tokens!") print(f" ๐Ÿšจ Content was CUT OFF - NOT COMPLETE") else: print(f" โœ… Response completed naturally") print() else: error = response.json().get('error', {}) print(f" โœ— Error: {error.get('message', 'Unknown')}\n") except Exception as e: print(f" โœ— Exception: {e}\n") print("=" * 70) print("๐ŸŽฏ CONCLUSION:") print("=" * 70) print("If any test shows 'TRUNCATED', we need higher max_tokens for content generation.") print("A 2000-word article needs ~2700 completion tokens minimum.") print()