image max count
This commit is contained in:
@@ -74,11 +74,11 @@ class AIEngine:
|
||||
elif function_name == 'generate_image_prompts':
|
||||
# Extract max_images from data if available
|
||||
if isinstance(data, list) and len(data) > 0:
|
||||
max_images = data[0].get('max_images', 2)
|
||||
max_images = data[0].get('max_images')
|
||||
total_images = 1 + max_images # 1 featured + max_images in-article
|
||||
return f"Mapping Content for {total_images} Image Prompts"
|
||||
elif isinstance(data, dict) and 'max_images' in data:
|
||||
max_images = data.get('max_images', 2)
|
||||
max_images = data.get('max_images')
|
||||
total_images = 1 + max_images
|
||||
return f"Mapping Content for {total_images} Image Prompts"
|
||||
return f"Mapping Content for Image Prompts"
|
||||
|
||||
@@ -93,7 +93,7 @@ class GenerateImagePromptsFunction(BaseAIFunction):
|
||||
data = data[0]
|
||||
|
||||
extracted = data['extracted']
|
||||
max_images = data.get('max_images', 2)
|
||||
max_images = data.get('max_images')
|
||||
|
||||
# Format content for prompt
|
||||
content_text = self._format_content_for_prompt(extracted)
|
||||
@@ -146,7 +146,7 @@ class GenerateImagePromptsFunction(BaseAIFunction):
|
||||
|
||||
content = original_data['content']
|
||||
extracted = original_data['extracted']
|
||||
max_images = original_data.get('max_images', 2)
|
||||
max_images = original_data.get('max_images')
|
||||
|
||||
prompts_created = 0
|
||||
|
||||
@@ -200,6 +200,14 @@ class GenerateImagePromptsFunction(BaseAIFunction):
|
||||
is_active=True
|
||||
)
|
||||
max_images = settings.config.get('max_in_article_images')
|
||||
|
||||
if max_images is None:
|
||||
raise ValueError(
|
||||
"max_in_article_images not configured in aws-admin image_generation settings. "
|
||||
"Please set this value in the Integration Settings page."
|
||||
)
|
||||
|
||||
max_images = int(max_images)
|
||||
logger.info(f"Using max_in_article_images={max_images} from aws-admin account")
|
||||
return max_images
|
||||
|
||||
|
||||
@@ -67,19 +67,17 @@ class GenerateImagesFunction(BaseAIFunction):
|
||||
if not tasks:
|
||||
raise ValueError("No tasks found")
|
||||
|
||||
# Get image generation settings
|
||||
image_settings = {}
|
||||
if account:
|
||||
try:
|
||||
# Get image generation settings from aws-admin account only (global settings)
|
||||
from igny8_core.modules.system.models import IntegrationSettings
|
||||
from igny8_core.auth.models import Account
|
||||
|
||||
system_account = Account.objects.get(slug='aws-admin')
|
||||
integration = IntegrationSettings.objects.get(
|
||||
account=account,
|
||||
account=system_account,
|
||||
integration_type='image_generation',
|
||||
is_active=True
|
||||
)
|
||||
image_settings = integration.config or {}
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Extract settings with defaults
|
||||
provider = image_settings.get('provider') or image_settings.get('service', 'openai')
|
||||
@@ -94,7 +92,7 @@ class GenerateImagesFunction(BaseAIFunction):
|
||||
'provider': provider,
|
||||
'model': model,
|
||||
'image_type': image_settings.get('image_type', 'realistic'),
|
||||
'max_in_article_images': int(image_settings.get('max_in_article_images', 2)),
|
||||
'max_in_article_images': int(image_settings.get('max_in_article_images')),
|
||||
'desktop_enabled': image_settings.get('desktop_enabled', True),
|
||||
'mobile_enabled': image_settings.get('mobile_enabled', True),
|
||||
}
|
||||
@@ -102,7 +100,7 @@ class GenerateImagesFunction(BaseAIFunction):
|
||||
def build_prompt(self, data: Dict, account=None) -> Dict:
|
||||
"""Extract image prompts from task content"""
|
||||
task = data.get('task')
|
||||
max_images = data.get('max_in_article_images', 2)
|
||||
max_images = data.get('max_in_article_images')
|
||||
|
||||
if not task or not task.content:
|
||||
raise ValueError("Task has no content")
|
||||
|
||||
@@ -182,19 +182,8 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
||||
results = []
|
||||
|
||||
# Get image generation settings from IntegrationSettings
|
||||
# Normal users use system account settings (aws-admin) via fallback
|
||||
logger.info("[process_image_generation_queue] Step 1: Loading image generation settings")
|
||||
try:
|
||||
image_settings = IntegrationSettings.objects.get(
|
||||
account=account,
|
||||
integration_type='image_generation',
|
||||
is_active=True
|
||||
)
|
||||
logger.info(f"[process_image_generation_queue] Image generation settings found for account {account.id}")
|
||||
config = image_settings.config or {}
|
||||
except IntegrationSettings.DoesNotExist:
|
||||
# Fallback to system account (aws-admin) settings
|
||||
logger.info(f"[process_image_generation_queue] No settings for account {account.id}, falling back to system account")
|
||||
# Always use system account settings (aws-admin) for global configuration
|
||||
logger.info("[process_image_generation_queue] Step 1: Loading image generation settings from aws-admin")
|
||||
from igny8_core.auth.models import Account
|
||||
try:
|
||||
system_account = Account.objects.get(slug='aws-admin')
|
||||
@@ -206,8 +195,8 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
||||
logger.info(f"[process_image_generation_queue] Using system account (aws-admin) settings")
|
||||
config = image_settings.config or {}
|
||||
except (Account.DoesNotExist, IntegrationSettings.DoesNotExist):
|
||||
logger.error("[process_image_generation_queue] ERROR: Image generation settings not found in system account either")
|
||||
return {'success': False, 'error': 'Image generation settings not found'}
|
||||
logger.error("[process_image_generation_queue] ERROR: Image generation settings not found in aws-admin account")
|
||||
return {'success': False, 'error': 'Image generation settings not found in aws-admin account'}
|
||||
except Exception as e:
|
||||
logger.error(f"[process_image_generation_queue] ERROR loading image generation settings: {e}", exc_info=True)
|
||||
return {'success': False, 'error': f'Error loading image generation settings: {str(e)}'}
|
||||
|
||||
@@ -733,9 +733,8 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
|
||||
config['model'] = config.get('imageModel', 'dall-e-3')
|
||||
elif config.get('provider') == 'runware' and 'model' not in config:
|
||||
config['model'] = config.get('runwareModel', 'runware:97@1')
|
||||
# Ensure all image settings have defaults
|
||||
# Ensure all image settings have defaults (except max_in_article_images which must be explicitly set)
|
||||
config.setdefault('image_type', 'realistic')
|
||||
config.setdefault('max_in_article_images', 2)
|
||||
config.setdefault('image_format', 'webp')
|
||||
config.setdefault('desktop_enabled', True)
|
||||
config.setdefault('mobile_enabled', True)
|
||||
@@ -899,20 +898,10 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
|
||||
)
|
||||
logger.info(f"[get_image_generation_settings] Using system account (aws-admin) settings")
|
||||
except (Account.DoesNotExist, IntegrationSettings.DoesNotExist):
|
||||
logger.error("[get_image_generation_settings] No image generation settings found in system account either")
|
||||
# Return default settings instead of error
|
||||
return success_response(
|
||||
data={
|
||||
'config': {
|
||||
'provider': 'openai',
|
||||
'model': 'dall-e-3',
|
||||
'image_type': 'realistic',
|
||||
'max_in_article_images': 2,
|
||||
'image_format': 'webp',
|
||||
'desktop_enabled': True,
|
||||
'mobile_enabled': True,
|
||||
}
|
||||
},
|
||||
logger.error("[get_image_generation_settings] No image generation settings found in aws-admin account")
|
||||
return error_response(
|
||||
error='Image generation settings not configured in aws-admin account',
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
request=request
|
||||
)
|
||||
|
||||
@@ -937,7 +926,7 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
|
||||
'provider': config.get('provider', 'openai'),
|
||||
'model': model,
|
||||
'image_type': config.get('image_type', 'realistic'),
|
||||
'max_in_article_images': config.get('max_in_article_images', 2),
|
||||
'max_in_article_images': config.get('max_in_article_images'),
|
||||
'image_format': config.get('image_format', 'webp'),
|
||||
'desktop_enabled': config.get('desktop_enabled', True),
|
||||
'mobile_enabled': config.get('mobile_enabled', True),
|
||||
@@ -948,18 +937,9 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
|
||||
request=request
|
||||
)
|
||||
except IntegrationSettings.DoesNotExist:
|
||||
return success_response(
|
||||
data={
|
||||
'config': {
|
||||
'provider': 'openai',
|
||||
'model': 'dall-e-3',
|
||||
'image_type': 'realistic',
|
||||
'max_in_article_images': 2,
|
||||
'image_format': 'webp',
|
||||
'desktop_enabled': True,
|
||||
'mobile_enabled': True,
|
||||
}
|
||||
},
|
||||
return error_response(
|
||||
error='Image generation settings not configured',
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
request=request
|
||||
)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user