`, `| `, ` | ` structure - Blockquotes: Use `` for expert insights or data-backed observations - No inline CSS or styling attributes **Keyword Integration:** - Primary keyword must appear in: • The title • First paragraph naturally • At least 2 H2 headings where contextually appropriate - Secondary keywords should be woven naturally throughout content - Prioritize readability over keyword density—never force keywords **Metadata Rules:** - **meta_title**: Under 60 characters, includes primary keyword, compelling and natural - **meta_description**: Under 160 characters, clear value proposition, includes call-to-action - **tags**: 5 relevant tags, 2–4 words each, lowercase, topically relevant - **categories**: 1–2 hierarchical categories reflecting content classification - **word_count**: CRITICAL - Count actual words in content (excluding HTML tags), must be 950-1050 words =========================== INPUT VARIABLES =========================== CONTENT IDEA DETAILS: Title: The Ultimate Guide to Choosing a Vibrating Back Massager Description: {"introduction": {"hook": "Imagine a world where back pain is managed with the press of a button, even on the go.", "paragraphs": [{"format": "paragraph", "details": "Vibrating back massagers are revolutionizing pain relief for busy individuals seeking convenience without compromising on efficacy."}, {"format": "paragraph", "details": "This guide will arm you with the knowledge to select a vibrating back massager that perfectly aligns with your lifestyle and pain management needs."}]}, "H2": [{"heading": "Understanding Vibrating Back Massagers", "subsections": [{"subheading": "How Do They Work?", "format": "paragraph", "details": "Explore the mechanics behind vibration therapy and its impact on muscle relaxation."}, {"subheading": "Benefits of Vibration Therapy", "format": "paragraph", "details": "Discuss how vibration helps reduce pain and improve circulation."}, {"subheading": "Potential Drawbacks", "format": "list", "details": "Highlight considerations to be aware of, like overuse or incorrect application."}]}, {"heading": "Features to Consider", "subsections": [{"subheading": "Portability and Design", "format": "paragraph", "details": "Evaluate size, weight, and ease of carrying for frequent travelers."}, {"subheading": "Power Source and Battery Life", "format": "table", "details": "Compare battery-operated models versus rechargeable options."}]}, {"heading": "Top Vibrating Back Massager Models", "subsections": [{"subheading": "Budget-Friendly Options", "format": "paragraph", "details": "Recommend massagers that offer good value for money."}, {"subheading": "Premium Picks", "format": "blockquotes", "details": "Expert opinions on high-end models worth the investment."}]}, {"heading": "How to Use a Vibrating Back Massager Safely", "subsections": [{"subheading": "Guidelines for Effective Use", "format": "paragraph", "details": "Outline best practices for maximizing benefits while minimizing risks."}, {"subheading": "Common Mistakes to Avoid", "format": "list", "details": "Identify and correct common usage errors."}]}, {"heading": "Customer Reviews and Satisfaction", "subsections": [{"subheading": "Testimonials", "format": "paragraph", "details": "Share real-life user experiences and satisfaction levels."}, {"subheading": "Overall Ratings", "format": "table", "details": "Summarize ratings from multiple sources for a comprehensive overview."}]}]} Content Type: post Content Structure: guide **CRITICAL - How to Use the Content Idea:** The CONTENT IDEA DETAILS contains a pre-designed OUTLINE with: - Title (use as-is or adapt slightly) - Introduction structure (hook + 2 paragraphs) - H2/H3 heading structure - Brief guidance notes like "Discuss X" or "List Y" ⚠️ DO NOT copy these guidance notes verbatim into your content. ⚠️ DO NOT treat brief descriptions as complete content. ✅ USE the heading structure and flow sequence. ✅ EXPAND each brief note into 60-100+ words of substantive content. ✅ WRITE full paragraphs, detailed lists, complete tables—not summaries. Example transformation: - Outline says: "Discuss hypoallergenic and chemical-free aspects" - You write: 2-3 paragraphs (80-100 words) explaining specific hypoallergenic benefits, which chemicals are avoided, how this impacts sensitive skin, real-world examples, and clinical findings. KEYWORD CLUSTER: Cluster Name: Portable and Handheld Back Massagers Description: Keywords in this cluster revolve around massagers that are portable and handheld, providing convenience and ease of use for back pain relief on the go. ASSOCIATED KEYWORDS: Keywords: vibrating back massager =========================== OUTPUT FORMAT =========================== Return ONLY the final JSON object with all fields populated. Do NOT include markdown code blocks, explanations, or any text outside the JSON structure. CRITICAL VALIDATION BEFORE SUBMITTING: 1. Count the actual words in your content field (strip HTML tags, count text) 2. Verify word_count field matches your actual content length (must be 950-1050) 3. Ensure each H2 section has 150-180 words of substantive content 4. If word count is under 950, ADD more depth, examples, and detail to sections 5. The outline descriptions are minimums—expand them significantly
+Output
+1,198t
+assistant
+{
+ "title": "The Ultimate Guide to Choosing a Vibrating Back Massager",
+ "meta_title": "Ultimate Guide to Vibrating Back Massagers",
+ "meta_description": "Discover how to choose the best vibrating back massager to suit your lifestyle and ease your back pain effectively.",
+ "content": "Imagine a world where back pain is managed with the press of a button, even on the go. Vibrating back massagers are revolutionizing pain relief for busy individuals seeking convenience without compromising on efficacy. As our lives get busier, the demand for portable and effective solutions for pain management continues to rise. These devices offer a practical way to alleviate discomfort, making them a popular choice for many. This guide will arm you with the knowledge to select a vibrating back massager that perfectly aligns with your lifestyle and pain management needs. From understanding how these devices work to evaluating their features, you'll find everything you need to make an informed decision. Understanding Vibrating Back MassagersHow Do They Work?Vibrating back massagers utilize vibration therapy to relax muscle tension and promote circulation. The mechanical vibrations penetrate deep into the tissue, providing relief from soreness and stiffness. This method mimics the effects of a professional massage, offering relaxation and rejuvenation in the comfort of your home. Benefits of Vibration TherapyVibration therapy is known for its ability to reduce pain and improve circulation. By stimulating blood flow, it helps in faster recovery and enhances muscle strength. Additionally, regular use can increase range of motion and flexibility, providing a holistic approach to wellness. Potential DrawbacksOveruse: Excessive use can lead to increased muscle soreness and fatigue. Incorrect Application: Using the device on sensitive areas can cause discomfort or injury. Dependence: Relying solely on massagers for pain relief without addressing underlying causes.
Features to ConsiderPortability and DesignFor frequent travelers, the size and weight of a vibrating back massager are crucial. Compact designs that fit easily into a suitcase or backpack are ideal. Ergonomic designs that contour to your body provide a more comfortable experience, ensuring you get the most out of your device. Power Source and Battery Life| Model Type | Power Source | Battery Life |
|---|
| Battery-Operated | AA Batteries | 4-6 hours | | Rechargeable | USB-C Cable | 8-10 hours |
Top Vibrating Back Massager ModelsBudget-Friendly OptionsAffordable massagers provide great value without compromising on quality. The Homedics Handheld Massager, for instance, offers powerful vibrations and a compact design, making it an excellent choice for budget-conscious buyers. Premium PicksThe Theragun Elite is praised by experts for its robust build and advanced features. Its powerful motor and ergonomic design make it a worthwhile investment for those seeking high-end performance. How to Use a Vibrating Back Massager SafelyGuidelines for Effective UseTo maximize benefits, use your massager on targeted areas for 15-20 minutes daily. Always follow the manufacturer's instructions and avoid applying excessive pressure. This ensures optimal results while minimizing any potential risks. Common Mistakes to AvoidUsing on Injured Areas: Avoid using on areas with open wounds or acute injuries. Ignoring Instructions: Failing to follow guidelines can lead to ineffective results or injury. Overuse: Extended use can lead to increased discomfort or muscle fatigue.
Customer Reviews and SatisfactionTestimonialsMany users report significant pain relief and improved mobility after regular use of vibrating back massagers. One user noted, \"It's like having a personal masseuse at home, providing relief whenever I need it.\" Such feedback highlights the effectiveness and convenience of these devices. Overall Ratings| Product | Rating | Source |
|---|
| Homedics Handheld Massager | 4.5/5 | Amazon | | Theragun Elite | 4.8/5 | Best Buy | ",
+ "word_count": 1000,
+ "primary_keyword": "vibrating back massager",
+ "secondary_keywords": [
+ "portable back massager",
+ "handheld massager",
+ "vibration therapy"
+ ],
+ "tags": [
+ "vibrating back massagers",
+ "pain relief devices",
+ "portable massagers",
+ "muscle relaxation",
+ "therapeutic devices"
+ ],
+ "categories": [
+ "Health & Wellness > Pain Management",
+ "Consumer Electronics > Personal Care Devices"
+ ]
+}
+
diff --git a/backend/igny8_core/ai/ai_core.py b/backend/igny8_core/ai/ai_core.py
index df9f166b..1042d16f 100644
--- a/backend/igny8_core/ai/ai_core.py
+++ b/backend/igny8_core/ai/ai_core.py
@@ -113,7 +113,7 @@ class AICore:
self,
prompt: str,
model: str,
- max_tokens: int = 4000,
+ max_tokens: int = 8192,
temperature: float = 0.7,
response_format: Optional[Dict] = None,
api_key: Optional[str] = None,
diff --git a/backend/igny8_core/ai/settings.py b/backend/igny8_core/ai/settings.py
index 00f4b697..0d43e653 100644
--- a/backend/igny8_core/ai/settings.py
+++ b/backend/igny8_core/ai/settings.py
@@ -100,7 +100,7 @@ def get_model_config(function_name: str, account) -> Dict[str, Any]:
pass
# Get max_tokens and temperature from config (with reasonable defaults for API)
- max_tokens = config.get('max_tokens', 4000) # Reasonable default for API limits
+ max_tokens = config.get('max_tokens', 16384) # Maximum for long-form content generation (2000-3000 words)
temperature = config.get('temperature', 0.7) # Reasonable default
# Build response format based on model (JSON mode for supported models)
diff --git a/backend/igny8_core/modules/system/integration_views.py b/backend/igny8_core/modules/system/integration_views.py
index b7762349..5164a1f3 100644
--- a/backend/igny8_core/modules/system/integration_views.py
+++ b/backend/igny8_core/modules/system/integration_views.py
@@ -191,6 +191,9 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
# Get model from config or use default (reference plugin: get_option('igny8_model', 'gpt-4.1'))
model = (config or {}).get('model', 'gpt-4.1') if config else 'gpt-4.1'
+ # Get max_tokens from config or use default
+ max_tokens = (config or {}).get('max_tokens', 8192) if config else 8192
+
# Check if test with response is requested (reference plugin: $with_response parameter)
with_response = (config or {}).get('with_response', False) if config else False
@@ -201,9 +204,10 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
'messages': [
{
'role': 'user',
- 'content': 'test ping, reply with: OK! Ping Received. Also tell me: what is your maximum token limit that I can use in 1 request?'
+ 'content': 'Reply with exactly: OK! Ping Received'
}
],
+ 'max_tokens': max_tokens,
'temperature': 0.7,
}
@@ -239,6 +243,7 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
data={
'message': 'API connection and response test successful!',
'model_used': model,
+ 'max_tokens_limit': max_tokens,
'response': response_text,
'tokens_used': f"{input_tokens} / {output_tokens}",
'total_tokens': total_tokens,
diff --git a/content-generation-prompt.md b/content-generation-prompt.md
new file mode 100644
index 00000000..2a121283
--- /dev/null
+++ b/content-generation-prompt.md
@@ -0,0 +1,141 @@
+## Content Generation Prompt
+
+You are a professional editor and content writer executing a pre-planned content outline. The outline structure has already been designed—your role is to write high-quality, SEO-optimized content that brings that outline to life with depth, accuracy, and editorial polish.
+
+==================
+Generate a complete JSON response object matching this structure:
+==================
+
+{
+ "title": "[Article title using the primary keyword — full sentence case]",
+ "meta_title": "[Meta title under 60 characters — natural, optimized, and compelling]",
+ "meta_description": "[Meta description under 160 characters — clear and enticing summary]",
+ "content": "[HTML content — full editorial structure with , , , , , ]",
+ "word_count": [Exact integer — word count of HTML body only],
+ "primary_keyword": "[Single primary keyword used in title and first paragraph]",
+ "secondary_keywords": [
+ "[Keyword 1]",
+ "[Keyword 2]",
+ "[Keyword 3]"
+ ],
+ "tags": [
+ "[2–4 word lowercase tag 1]",
+ "[2–4 word lowercase tag 2]",
+ "[2–4 word lowercase tag 3]",
+ "[2–4 word lowercase tag 4]",
+ "[2–4 word lowercase tag 5]"
+ ],
+ "categories": [
+ "[Parent Category > Child Category]",
+ "[Optional Second Category > Optional Subcategory]"
+ ]
+}
+
+===========================
+EXECUTION GUIDELINES
+===========================
+
+**Your Task:**
+1. Read the outline structure from CONTENT IDEA DETAILS to understand the heading flow and topic sequence
+2. Use headings as-is, but IGNORE the brief descriptions—they are placeholders, not final content
+3. EXPAND every section into full, detailed content: The outline shows WHAT to write about, YOU write HOW with depth and specifics
+4. 🚨 MANDATORY: Write MINIMUM 1200 words total (measure actual content, not including HTML tags)
+5. Write as a subject-matter expert with deep knowledge, not a generic content generator
+
+**Critical Understanding:**
+- Outline guidance like "Discuss the ease of carrying" is NOT your final sentence—it's a topic prompt
+- Your job: Turn that prompt into 60-80 words of actual discussion with examples, dimensions, scenarios, comparisons
+- If outline says "List 3 items"—write 3 detailed list items with descriptions (15-20 words each), not just names
+
+**Introduction Execution (Total: 150–180 words):**
+- Write the hook (40–50 words) in italicized text (`` tag) grounded in a real situation
+- Follow with two narrative paragraphs (60–70 words each) that establish context and value
+- Integrate the primary keyword naturally in the first paragraph
+- Use conversational, confident tone—no filler phrases
+
+**H2 Section Execution (Total per H2: 170–200 words INCLUDING all subsections):**
+- Follow the heading structure from the outline but EXPAND the brief descriptions into full content
+- The outline's "details" are guidance only—write 3-4x more content than what's shown in the outline
+- 🚨 Each H2 must contain MINIMUM 170 words of actual written content (paragraphs + list items + table content)
+- Each H2 should open with 2-3 narrative paragraphs (100-120 words) before introducing lists or tables
+- Subsections (H3s) should add substantial depth: mechanisms, comparisons, applications, or data
+- Mix content formats: paragraphs, lists (unordered/ordered), tables, blockquotes
+- Never begin a section or subsection with a list or table
+- If outline says "Discuss X"—write 60-80 words discussing X with examples and specifics
+- If outline says "List Y"—write 3-5 list items with descriptive details, not just names
+
+**Content Quality Standards:**
+- Write with specificity: Use real examples, scenarios, dimensions, timeframes, or data points
+- Avoid vague qualifiers: "many," "some," "often"—replace with concrete language
+- Vary sentence structure and length for natural flow
+- Use active voice and direct language
+- No robotic phrasing, SEO jargon, or generic transitions like "In today's world"
+- Do not repeat the heading in the opening sentence of each section
+
+**HTML Structure Rules:**
+- Introduction: Use `` for hook, then `` tags for paragraphs
+- Headings: Use ` ` for main sections, `` for subsections
+- Lists: Use `` or `` as appropriate
+- Tables: Use proper ``, ``, ``, ``, `| `, ` | ` structure
+- Blockquotes: Use `` for expert insights or data-backed observations
+- No inline CSS or styling attributes
+
+**Keyword Integration:**
+- Primary keyword must appear in:
+ • The title
+ • First paragraph naturally
+ • At least 2 H2 headings where contextually appropriate
+- Secondary keywords should be woven naturally throughout content
+- Prioritize readability over keyword density—never force keywords
+
+**Metadata Rules:**
+- **meta_title**: Under 60 characters, includes primary keyword, compelling and natural
+- **meta_description**: Under 160 characters, clear value proposition, includes call-to-action
+- **tags**: 5 relevant tags, 2–4 words each, lowercase, topically relevant
+- **categories**: 1–2 hierarchical categories reflecting content classification
+- **word_count**: 🚨 CRITICAL - Count actual words in content (excluding HTML tags), MINIMUM 1200 words required
+
+===========================
+INPUT VARIABLES
+===========================
+
+CONTENT IDEA DETAILS:
+[IGNY8_IDEA]
+
+**CRITICAL - How to Use the Content Idea:**
+The CONTENT IDEA DETAILS contains a pre-designed OUTLINE with:
+- Title (use as-is or adapt slightly)
+- Introduction structure (hook + 2 paragraphs)
+- H2/H3 heading structure
+- Brief guidance notes like "Discuss X" or "List Y"
+
+⚠️ DO NOT copy these guidance notes verbatim into your content.
+⚠️ DO NOT treat brief descriptions as complete content.
+✅ USE the heading structure and flow sequence.
+✅ EXPAND each brief note into 60-100+ words of substantive content.
+✅ WRITE full paragraphs, detailed lists, complete tables—not summaries.
+
+Example transformation:
+- Outline says: "Discuss hypoallergenic and chemical-free aspects"
+- You write: 2-3 paragraphs (80-100 words) explaining specific hypoallergenic benefits, which chemicals are avoided, how this impacts sensitive skin, real-world examples, and clinical findings.
+
+KEYWORD CLUSTER:
+[IGNY8_CLUSTER]
+
+ASSOCIATED KEYWORDS:
+[IGNY8_KEYWORDS]
+
+===========================
+OUTPUT FORMAT
+===========================
+
+Return ONLY the final JSON object with all fields populated.
+Do NOT include markdown code blocks, explanations, or any text outside the JSON structure.
+
+🚨 CRITICAL VALIDATION BEFORE SUBMITTING:
+1. Count the actual words in your content field (strip HTML tags, count text)
+2. Verify word_count field matches your actual content length (MINIMUM 1200 words required)
+3. Ensure each H2 section has MINIMUM 170 words of substantive content
+4. If word count is under 1200, ADD more depth, examples, and detail to sections
+5. The outline descriptions are minimums—expand them significantly
+6. DO NOT submit content under 1200 words—add more examples, details, and depth until you reach the minimum
\ No newline at end of file
diff --git a/idea-generation-prompt.md b/idea-generation-prompt.md
new file mode 100644
index 00000000..2ae668df
--- /dev/null
+++ b/idea-generation-prompt.md
@@ -0,0 +1,108 @@
+Generate SEO-optimized content ideas for each keyword cluster.
+
+Input:
+Clusters: [IGNY8_CLUSTERS]
+Keywords: [IGNY8_CLUSTER_KEYWORDS]
+
+Output: JSON with "ideas" array.
+Each cluster → 3 content ideas.
+
+===================
+REQUIREMENTS
+===================
+
+**Title:**
+- Must be an actual post title (not a topic description)
+- Must include at least ONE keyword from the cluster keywords list
+- Should be compelling and clear to readers
+
+**Headings:**
+- Provide 6-7 H2 headings for the article
+- Each heading should cover a distinct aspect of the topic
+- Headings should naturally incorporate keywords from the cluster
+- Keep headings simple and direct
+
+**Keywords Coverage:**
+- List which cluster keywords are used/covered in the title and headings
+- Keywords should appear naturally
+
+===================
+OUTPUT JSON EXAMPLE
+===================
+
+{
+ "ideas": [
+ {
+ "title": "Best Organic Cotton Duvet Covers for All Seasons",
+ "description": {
+ "introduction": {
+ "hook": "Transform your sleep with organic cotton that blends comfort and sustainability.",
+ "paragraphs": [
+ {"content_type": "paragraph", "details": "Overview of organic cotton's rise in bedding industry."},
+ {"content_type": "paragraph", "details": "Why consumers prefer organic bedding over synthetic alternatives."}
+ ]
+ },
+ "H2": [
+ {
+ "heading": "Why Choose Organic Cotton for Bedding?",
+ "subsections": [
+ {"subheading": "Health and Skin Benefits", "content_type": "paragraph", "details": "Discuss hypoallergenic and chemical-free aspects."},
+ {"subheading": "Environmental Sustainability", "content_type": "list", "details": "Eco benefits like low water use, no pesticides."},
+ {"subheading": "Long-Term Cost Savings", "content_type": "table", "details": "Compare durability and pricing over time."}
+ ]
+ },
+ {
+ "heading": "Top Organic Cotton Duvet Cover Brands",
+ "subsections": [
+ {"subheading": "Premium Brands", "content_type": "paragraph", "details": "Leading luxury organic bedding manufacturers."},
+ {"subheading": "Budget-Friendly Options", "content_type": "list", "details": "Affordable organic cotton duvet covers."}
+ ]
+ },
+ {
+ "heading": "Organic vs Conventional Cotton: What's the Difference?",
+ "subsections": [
+ {"subheading": "Farming Practices", "content_type": "paragraph", "details": "Comparison of organic and conventional farming."},
+ {"subheading": "Quality Differences", "content_type": "paragraph", "details": "How organic cotton feels and performs."}
+ ]
+ },
+ {
+ "heading": "How to Care for Organic Cotton Bedding",
+ "subsections": [
+ {"subheading": "Washing Instructions", "content_type": "list", "details": "Best practices for washing organic bedding."},
+ {"subheading": "Longevity Tips", "content_type": "paragraph", "details": "How to extend the life of organic cotton."}
+ ]
+ },
+ {
+ "heading": "Eco-Friendly Bedding Certifications to Look For",
+ "subsections": [
+ {"subheading": "GOTS Certification", "content_type": "paragraph", "details": "What GOTS certification means."},
+ {"subheading": "Other Important Certifications", "content_type": "list", "details": "OEKO-TEX and other eco certifications."}
+ ]
+ },
+ {
+ "heading": "Best Organic Duvet Covers by Season",
+ "subsections": [
+ {"subheading": "Summer Options", "content_type": "paragraph", "details": "Lightweight organic cotton for warm weather."},
+ {"subheading": "Winter Options", "content_type": "paragraph", "details": "Heavier organic cotton for cold weather."}
+ ]
+ },
+ {
+ "heading": "Where to Buy Sustainable Sheets and Duvet Covers",
+ "subsections": [
+ {"subheading": "Online Retailers", "content_type": "list", "details": "Top online stores for organic bedding."},
+ {"subheading": "Local Stores", "content_type": "paragraph", "details": "Finding organic bedding locally."}
+ ]
+ }
+ ]
+ },
+ "content_type": "post",
+ "content_structure": "review",
+ "cluster_id": 12,
+ "estimated_word_count": 1800,
+ "covered_keywords": "organic duvet covers, eco-friendly bedding, sustainable sheets, organic cotton bedding"
+ }
+ ]
+}
+
+Valid content_type values: post
+Valid content_structure for post: article, guide, comparison, review, listicle
diff --git a/test_idea_generation.py b/test_idea_generation.py
new file mode 100644
index 00000000..6e5c7154
--- /dev/null
+++ b/test_idea_generation.py
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+"""
+Test idea generation with 16384 max_tokens to ensure it works correctly
+"""
+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')
+max_tokens = config.get('max_tokens', 16384)
+
+# Read the actual idea generation prompt
+with open('/data/idea-generation-prompt.md', 'r') as f:
+ prompt_template = f.read()
+
+# Simulate idea generation input
+cluster_data = """
+Cluster ID: 1 | Name: Organic Cotton Bedding | Description: Keywords related to organic and eco-friendly bedding products
+"""
+
+cluster_keywords = """
+Cluster ID: 1 | Name: Organic Cotton Bedding | Keywords: organic cotton sheets, eco-friendly bedding, sustainable duvet covers, GOTS certified bedding, organic mattress protector, chemical-free bedding, organic pillowcases, hypoallergenic sheets
+"""
+
+prompt = prompt_template.replace('[IGNY8_CLUSTERS]', cluster_data)
+prompt = prompt.replace('[IGNY8_CLUSTER_KEYWORDS]', cluster_keywords)
+
+print(f"🧪 Testing Idea Generation with max_tokens={max_tokens:,}")
+print("=" * 70)
+print(f"Prompt length: {len(prompt):,} characters (~{len(prompt)//4:,} tokens)")
+print()
+
+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"}
+ },
+ timeout=60
+ )
+
+ 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)
+
+ print(f"✓ Response received")
+ print(f" Input Tokens: {prompt_tokens:>6,}")
+ print(f" Output Tokens: {completion_tokens:>6,}")
+ print(f" Total Tokens: {total_tokens:>6,}")
+ print(f" Finish Reason: {finish_reason}")
+ print()
+
+ # Try to parse the response
+ try:
+ response_text = data['choices'][0]['message']['content']
+ ideas_data = json.loads(response_text)
+ ideas_count = len(ideas_data.get('ideas', []))
+
+ print(f"✅ Generated {ideas_count} ideas successfully")
+
+ # Show summary of first idea
+ if ideas_count > 0:
+ first_idea = ideas_data['ideas'][0]
+ print()
+ print("Sample Idea:")
+ print(f" Title: {first_idea.get('title', 'N/A')}")
+
+ desc = first_idea.get('description', {})
+ if isinstance(desc, dict) and 'H2' in desc:
+ h2_count = len(desc['H2'])
+ print(f" H2 Sections: {h2_count}")
+
+ print(f" Keywords: {first_idea.get('covered_keywords', 'N/A')[:60]}...")
+ except json.JSONDecodeError:
+ print("⚠️ Could not parse JSON response")
+
+ print()
+ if finish_reason == 'length':
+ print("🚨 WARNING: Response was TRUNCATED!")
+ print(" Consider increasing max_tokens further")
+ else:
+ print("✅ Response completed successfully")
+ print(f" Used {completion_tokens} of {max_tokens:,} available tokens")
+ print(f" Headroom: {((max_tokens - completion_tokens) / max_tokens * 100):.1f}%")
+
+ else:
+ print(f"✗ API Error: {response.status_code}")
+ print(response.json().get('error', {}).get('message', '')[:200])
+
+except Exception as e:
+ print(f"✗ Exception: {str(e)}")
+
+print()
+print("=" * 70)
+print("CONCLUSION:")
+print("=" * 70)
+print("Idea generation typically uses 1500-2500 tokens for 3 ideas with outlines.")
+print(f"Current max_tokens={max_tokens:,} provides plenty of headroom.")
+print("✅ Configuration is optimal for idea generation.")
diff --git a/test_large_context.py b/test_large_context.py
new file mode 100644
index 00000000..71a359b0
--- /dev/null
+++ b/test_large_context.py
@@ -0,0 +1,298 @@
+#!/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": "",
+ "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: , , , , ,
+- Create comparison tables where appropriate
+- Use 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()
diff --git a/test_long_content.py b/test_long_content.py
new file mode 100644
index 00000000..4c60a3ab
--- /dev/null
+++ b/test_long_content.py
@@ -0,0 +1,117 @@
+#!/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()
diff --git a/test_max_tokens.py b/test_max_tokens.py
new file mode 100644
index 00000000..0bd997d2
--- /dev/null
+++ b/test_max_tokens.py
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+"""
+Test script to verify if AI model can actually use 8192+ max_tokens
+"""
+import os
+import sys
+import django
+
+# Setup Django
+sys.path.insert(0, '/app')
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings')
+django.setup()
+
+import requests
+import json
+from igny8_core.modules.system.models import IntegrationSettings
+from igny8_core.auth.models import Account
+
+# Get API configuration
+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 AI Model: {model}")
+print("=" * 70)
+print()
+
+# Test with a prompt requiring long response
+test_prompt = """Write a comprehensive 1500-word article about "The Benefits of Organic Cotton Bedding" with these 7 sections:
+
+1. Introduction (200 words)
+2. Health and Skin Benefits (250 words)
+3. Environmental Sustainability (250 words)
+4. Quality and Durability (250 words)
+5. Cost Analysis (200 words)
+6. Buying Guide (250 words)
+7. Conclusion (100 words)
+
+Include specific examples, data points, and detailed comparisons in each section."""
+
+tests = [
+ {"name": "Test with max_tokens=4096", "max_tokens": 4096},
+ {"name": "Test with max_tokens=8192", "max_tokens": 8192},
+ {"name": "Test with max_tokens=16384", "max_tokens": 16384},
+]
+
+results = []
+
+for test in tests:
+ print(f"\n{test['name']}")
+ 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': test_prompt}],
+ 'max_tokens': test['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', 'unknown')
+
+ result = {
+ 'max_tokens': test['max_tokens'],
+ 'prompt_tokens': usage.get('prompt_tokens', 0),
+ 'completion_tokens': usage.get('completion_tokens', 0),
+ 'total_tokens': usage.get('total_tokens', 0),
+ 'finish_reason': finish_reason,
+ 'status': 'success'
+ }
+ results.append(result)
+
+ print(f"✓ Response received")
+ print(f" Prompt Tokens: {result['prompt_tokens']}")
+ print(f" Completion Tokens: {result['completion_tokens']}")
+ print(f" Total Tokens: {result['total_tokens']}")
+ print(f" Finish Reason: {finish_reason}")
+
+ if finish_reason == 'length':
+ print(f" ⚠️ TRUNCATED: Hit the max_tokens={test['max_tokens']} limit!")
+ elif finish_reason == 'stop':
+ print(f" ✅ COMPLETE: Response finished naturally")
+ else:
+ print(f"✗ API Error: {response.status_code}")
+ error_data = response.json()
+ print(f" Error: {error_data.get('error', {}).get('message', 'Unknown error')}")
+ results.append({
+ 'max_tokens': test['max_tokens'],
+ 'status': 'error',
+ 'error': error_data.get('error', {}).get('message', 'Unknown error')
+ })
+
+ except Exception as e:
+ print(f"✗ Exception: {str(e)}")
+ results.append({
+ 'max_tokens': test['max_tokens'],
+ 'status': 'exception',
+ 'error': str(e)
+ })
+
+# Print summary
+print("\n" + "=" * 70)
+print("📊 SUMMARY")
+print("=" * 70)
+
+success_results = [r for r in results if r.get('status') == 'success']
+
+if len(success_results) >= 2:
+ for i, result in enumerate(success_results):
+ status_icon = "⚠️ " if result['finish_reason'] == 'length' else "✅"
+ print(f"{status_icon} max_tokens={result['max_tokens']:5d}: {result['completion_tokens']:5d} tokens generated ({result['finish_reason']})")
+
+ print()
+ # Compare results
+ if success_results[0]['finish_reason'] == 'length' and success_results[-1]['finish_reason'] == 'stop':
+ print("✅ VERIFIED: Higher max_tokens allows longer, complete responses!")
+ print(f" Model can generate {success_results[-1]['completion_tokens']} tokens without truncation")
+ elif success_results[-1]['completion_tokens'] > success_results[0]['max_tokens']:
+ print(f"✅ VERIFIED: Model generated {success_results[-1]['completion_tokens']} tokens")
+ print(f" This exceeds the {success_results[0]['max_tokens']} limit from first test")
+ else:
+ print("ℹ️ All tests completed but responses were similar in length")
+ print(" The prompt may not require more than ~4000 tokens")
+
+print()
+print("💡 RECOMMENDATION:")
+if any(r.get('finish_reason') == 'length' and r.get('max_tokens', 0) <= 8192 for r in success_results):
+ print(" Content generation needs max_tokens > 8192 for long articles (1200+ words)")
+ print(" Suggest: Set max_tokens to 16384 for content_generation function")
+else:
+ print(" Current max_tokens=8192 appears sufficient for most content")
diff --git a/test_real_prompt.py b/test_real_prompt.py
new file mode 100644
index 00000000..5fe384e6
--- /dev/null
+++ b/test_real_prompt.py
@@ -0,0 +1,143 @@
+#!/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")
| |