ai fixes
This commit is contained in:
129
backend/test_generate_content_simple.py
Normal file
129
backend/test_generate_content_simple.py
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Simple test to check generate_content function execution
|
||||
Run this to see exact error messages
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
import logging
|
||||
import json
|
||||
|
||||
# Setup Django
|
||||
sys.path.insert(0, '/data/app/igny8/backend')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'igny8_core.settings')
|
||||
django.setup()
|
||||
|
||||
# Setup logging to see all messages
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)s [%(levelname)s] %(name)s: %(message)s'
|
||||
)
|
||||
|
||||
from igny8_core.auth.models import Account
|
||||
from igny8_core.modules.writer.models import Tasks
|
||||
from igny8_core.ai.registry import get_function_instance
|
||||
from igny8_core.ai.engine import AIEngine
|
||||
|
||||
print("\n" + "="*80)
|
||||
print("SIMPLE GENERATE_CONTENT TEST")
|
||||
print("="*80 + "\n")
|
||||
|
||||
# Get first account and task
|
||||
try:
|
||||
account = Account.objects.first()
|
||||
print(f"✓ Account: {account.id} - {account.email}")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to get account: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
task = Tasks.objects.filter(account=account).first()
|
||||
if not task:
|
||||
print("✗ No tasks found")
|
||||
sys.exit(1)
|
||||
print(f"✓ Task: {task.id} - {task.title or 'Untitled'}")
|
||||
print(f" Status: {task.status}")
|
||||
print(f" Cluster: {task.cluster.name if task.cluster else 'None'}")
|
||||
print(f" Taxonomy: {task.taxonomy_term.name if task.taxonomy_term else 'None'}")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to get task: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Get function
|
||||
try:
|
||||
fn = get_function_instance('generate_content')
|
||||
print(f"✓ Function loaded: {fn.get_name()}")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to load function: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
# Test validation
|
||||
print("\nTesting validation...")
|
||||
try:
|
||||
payload = {'ids': [task.id]}
|
||||
result = fn.validate(payload, account)
|
||||
if result['valid']:
|
||||
print(f"✓ Validation passed")
|
||||
else:
|
||||
print(f"✗ Validation failed: {result.get('error')}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"✗ Validation error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
# Test prepare
|
||||
print("\nTesting prepare...")
|
||||
try:
|
||||
data = fn.prepare(payload, account)
|
||||
print(f"✓ Prepare succeeded: {len(data) if isinstance(data, list) else 1} task(s)")
|
||||
except Exception as e:
|
||||
print(f"✗ Prepare error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
# Test build_prompt
|
||||
print("\nTesting build_prompt...")
|
||||
try:
|
||||
prompt = fn.build_prompt(data, account)
|
||||
print(f"✓ Prompt built: {len(prompt)} characters")
|
||||
print(f"\nPrompt preview (first 500 chars):")
|
||||
print("-" * 80)
|
||||
print(prompt[:500])
|
||||
print("-" * 80)
|
||||
except Exception as e:
|
||||
print(f"✗ Build prompt error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
# Test model config
|
||||
print("\nTesting model config...")
|
||||
try:
|
||||
from igny8_core.ai.settings import get_model_config
|
||||
model_config = get_model_config('generate_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"✗ Model config error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
print("\n" + "="*80)
|
||||
print("All tests passed! The function structure is correct.")
|
||||
print("If content generation still fails, the issue is likely:")
|
||||
print("1. API key is invalid or missing")
|
||||
print("2. OpenAI API error (rate limit, quota, etc.)")
|
||||
print("3. Prompt is too long or has invalid format")
|
||||
print("4. Celery worker is not running or has errors")
|
||||
print("\nCheck Celery worker logs with:")
|
||||
print(" journalctl -u celery-worker -f")
|
||||
print("="*80 + "\n")
|
||||
Reference in New Issue
Block a user