phase 8
This commit is contained in:
@@ -72,4 +72,201 @@ class ContentGenerationService:
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}
|
||||
|
||||
def generate_product_content(self, product_data, account, site=None, sector=None):
|
||||
"""
|
||||
Generate product content.
|
||||
|
||||
Args:
|
||||
product_data: Dict with product information (name, description, features, etc.)
|
||||
account: Account instance
|
||||
site: Site instance (optional)
|
||||
sector: Sector instance (optional)
|
||||
|
||||
Returns:
|
||||
dict: Result with success status and data
|
||||
|
||||
Raises:
|
||||
InsufficientCreditsError: If account doesn't have enough credits
|
||||
"""
|
||||
# Calculate estimated credits needed (default 1500 words for product content)
|
||||
estimated_word_count = product_data.get('word_count', 1500)
|
||||
|
||||
# Check credits
|
||||
try:
|
||||
self.credit_service.check_credits(account, 'content_generation', estimated_word_count)
|
||||
except InsufficientCreditsError:
|
||||
raise
|
||||
|
||||
# Delegate to AI task
|
||||
from igny8_core.ai.tasks import run_ai_task
|
||||
|
||||
try:
|
||||
payload = {
|
||||
'product_name': product_data.get('name', ''),
|
||||
'product_description': product_data.get('description', ''),
|
||||
'product_features': product_data.get('features', []),
|
||||
'target_audience': product_data.get('target_audience', ''),
|
||||
'primary_keyword': product_data.get('primary_keyword', ''),
|
||||
'site_id': site.id if site else None,
|
||||
'sector_id': sector.id if sector else None,
|
||||
}
|
||||
|
||||
if hasattr(run_ai_task, 'delay'):
|
||||
# Celery available - queue async
|
||||
task = run_ai_task.delay(
|
||||
function_name='generate_product_content',
|
||||
payload=payload,
|
||||
account_id=account.id
|
||||
)
|
||||
return {
|
||||
'success': True,
|
||||
'task_id': str(task.id),
|
||||
'message': 'Product content generation started'
|
||||
}
|
||||
else:
|
||||
# Celery not available - execute synchronously
|
||||
result = run_ai_task(
|
||||
function_name='generate_product_content',
|
||||
payload=payload,
|
||||
account_id=account.id
|
||||
)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"Error in generate_product_content: {str(e)}", exc_info=True)
|
||||
return {
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}
|
||||
|
||||
def generate_service_page(self, service_data, account, site=None, sector=None):
|
||||
"""
|
||||
Generate service page content.
|
||||
|
||||
Args:
|
||||
service_data: Dict with service information (name, description, benefits, etc.)
|
||||
account: Account instance
|
||||
site: Site instance (optional)
|
||||
sector: Sector instance (optional)
|
||||
|
||||
Returns:
|
||||
dict: Result with success status and data
|
||||
|
||||
Raises:
|
||||
InsufficientCreditsError: If account doesn't have enough credits
|
||||
"""
|
||||
# Calculate estimated credits needed (default 1800 words for service page)
|
||||
estimated_word_count = service_data.get('word_count', 1800)
|
||||
|
||||
# Check credits
|
||||
try:
|
||||
self.credit_service.check_credits(account, 'content_generation', estimated_word_count)
|
||||
except InsufficientCreditsError:
|
||||
raise
|
||||
|
||||
# Delegate to AI task
|
||||
from igny8_core.ai.tasks import run_ai_task
|
||||
|
||||
try:
|
||||
payload = {
|
||||
'service_name': service_data.get('name', ''),
|
||||
'service_description': service_data.get('description', ''),
|
||||
'service_benefits': service_data.get('benefits', []),
|
||||
'target_audience': service_data.get('target_audience', ''),
|
||||
'primary_keyword': service_data.get('primary_keyword', ''),
|
||||
'site_id': site.id if site else None,
|
||||
'sector_id': sector.id if sector else None,
|
||||
}
|
||||
|
||||
if hasattr(run_ai_task, 'delay'):
|
||||
# Celery available - queue async
|
||||
task = run_ai_task.delay(
|
||||
function_name='generate_service_page',
|
||||
payload=payload,
|
||||
account_id=account.id
|
||||
)
|
||||
return {
|
||||
'success': True,
|
||||
'task_id': str(task.id),
|
||||
'message': 'Service page generation started'
|
||||
}
|
||||
else:
|
||||
# Celery not available - execute synchronously
|
||||
result = run_ai_task(
|
||||
function_name='generate_service_page',
|
||||
payload=payload,
|
||||
account_id=account.id
|
||||
)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"Error in generate_service_page: {str(e)}", exc_info=True)
|
||||
return {
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}
|
||||
|
||||
def generate_taxonomy(self, taxonomy_data, account, site=None, sector=None):
|
||||
"""
|
||||
Generate taxonomy page content.
|
||||
|
||||
Args:
|
||||
taxonomy_data: Dict with taxonomy information (name, description, items, etc.)
|
||||
account: Account instance
|
||||
site: Site instance (optional)
|
||||
sector: Sector instance (optional)
|
||||
|
||||
Returns:
|
||||
dict: Result with success status and data
|
||||
|
||||
Raises:
|
||||
InsufficientCreditsError: If account doesn't have enough credits
|
||||
"""
|
||||
# Calculate estimated credits needed (default 1200 words for taxonomy page)
|
||||
estimated_word_count = taxonomy_data.get('word_count', 1200)
|
||||
|
||||
# Check credits
|
||||
try:
|
||||
self.credit_service.check_credits(account, 'content_generation', estimated_word_count)
|
||||
except InsufficientCreditsError:
|
||||
raise
|
||||
|
||||
# Delegate to AI task
|
||||
from igny8_core.ai.tasks import run_ai_task
|
||||
|
||||
try:
|
||||
payload = {
|
||||
'taxonomy_name': taxonomy_data.get('name', ''),
|
||||
'taxonomy_description': taxonomy_data.get('description', ''),
|
||||
'taxonomy_items': taxonomy_data.get('items', []),
|
||||
'primary_keyword': taxonomy_data.get('primary_keyword', ''),
|
||||
'site_id': site.id if site else None,
|
||||
'sector_id': sector.id if sector else None,
|
||||
}
|
||||
|
||||
if hasattr(run_ai_task, 'delay'):
|
||||
# Celery available - queue async
|
||||
task = run_ai_task.delay(
|
||||
function_name='generate_taxonomy',
|
||||
payload=payload,
|
||||
account_id=account.id
|
||||
)
|
||||
return {
|
||||
'success': True,
|
||||
'task_id': str(task.id),
|
||||
'message': 'Taxonomy generation started'
|
||||
}
|
||||
else:
|
||||
# Celery not available - execute synchronously
|
||||
result = run_ai_task(
|
||||
function_name='generate_taxonomy',
|
||||
payload=payload,
|
||||
account_id=account.id
|
||||
)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error(f"Error in generate_taxonomy: {str(e)}", exc_info=True)
|
||||
return {
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user