From 8c1d933647f665fd90fcaa8fafd663ab53470aa7 Mon Sep 17 00:00:00 2001 From: "IGNY8 VPS (Salman)" Date: Wed, 17 Dec 2025 12:35:43 +0000 Subject: [PATCH] max iamges --- .../ai/functions/generate_image_prompts.py | 36 ++++++++++++++----- backend/igny8_core/ai/prompts.py | 2 +- backend/igny8_core/ai/tasks.py | 2 +- backend/igny8_core/modules/system/utils.py | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/backend/igny8_core/ai/functions/generate_image_prompts.py b/backend/igny8_core/ai/functions/generate_image_prompts.py index 179a790b..c814662c 100644 --- a/backend/igny8_core/ai/functions/generate_image_prompts.py +++ b/backend/igny8_core/ai/functions/generate_image_prompts.py @@ -188,16 +188,36 @@ class GenerateImagePromptsFunction(BaseAIFunction): # Helper methods def _get_max_in_article_images(self, account) -> int: - """Get max_in_article_images from IntegrationSettings""" + """Get max_in_article_images from IntegrationSettings with fallback to system account""" try: from igny8_core.modules.system.models import IntegrationSettings - settings = IntegrationSettings.objects.get( - account=account, - integration_type='image_generation' - ) - return settings.config.get('max_in_article_images', 2) - except IntegrationSettings.DoesNotExist: - return 2 # Default + from igny8_core.auth.models import Account + + # Try account-specific settings first + try: + settings = IntegrationSettings.objects.get( + account=account, + integration_type='image_generation', + is_active=True + ) + max_images = settings.config.get('max_in_article_images', 2) + logger.info(f"Using max_in_article_images={max_images} from account {account.id} settings") + return max_images + except IntegrationSettings.DoesNotExist: + # Fallback to system account (aws-admin) + logger.info(f"No image_generation settings for account {account.id}, falling back to system account") + system_account = Account.objects.get(slug='aws-admin') + settings = IntegrationSettings.objects.get( + account=system_account, + integration_type='image_generation', + is_active=True + ) + max_images = settings.config.get('max_in_article_images', 2) + logger.info(f"Using max_in_article_images={max_images} from system account (aws-admin)") + return max_images + except Exception as e: + logger.warning(f"Failed to get max_in_article_images from IntegrationSettings: {e}, using default=2") + return 2 # Default fallback def _extract_content_elements(self, content: Content, max_images: int) -> Dict: """Extract title, intro paragraphs, and H2 headings from content HTML""" diff --git a/backend/igny8_core/ai/prompts.py b/backend/igny8_core/ai/prompts.py index 78048d73..d95e65bf 100644 --- a/backend/igny8_core/ai/prompts.py +++ b/backend/igny8_core/ai/prompts.py @@ -333,7 +333,7 @@ Return a JSON object with this structure: Make sure each prompt is detailed enough for image generation, describing the visual elements, style, mood, and composition.""", - 'image_prompt_template': 'Create a high-quality {image_type} image to use as a featured photo for a blog post titled "{post_title}". The image should visually represent the theme, mood, and subject implied by the image prompt: {image_prompt}. Focus on a realistic, well-composed scene that naturally communicates the topic without text or logos. Use balanced lighting, pleasing composition, and photographic detail suitable for lifestyle or editorial web content. Avoid adding any visible or readable text, brand names, or illustrative effects. **And make sure image is not blurry.**', + 'image_prompt_template': '{image_type} image for blog post titled "{post_title}": {image_prompt}', 'negative_prompt': 'text, watermark, logo, overlay, title, caption, writing on walls, writing on objects, UI, infographic elements, post title', diff --git a/backend/igny8_core/ai/tasks.py b/backend/igny8_core/ai/tasks.py index e5f62ac3..1b478f6a 100644 --- a/backend/igny8_core/ai/tasks.py +++ b/backend/igny8_core/ai/tasks.py @@ -285,7 +285,7 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None image_prompt_template = PromptRegistry.get_image_prompt_template(account) except Exception as e: logger.warning(f"Failed to get image prompt template: {e}, using fallback") - image_prompt_template = 'Create a high-quality {image_type} image for a blog post titled "{post_title}". Image prompt: {image_prompt}' + image_prompt_template = '{image_type} image for blog post titled "{post_title}": {image_prompt}' # Get negative prompt for Runware (only needed for Runware provider) negative_prompt = None diff --git a/backend/igny8_core/modules/system/utils.py b/backend/igny8_core/modules/system/utils.py index 613dff80..320f7331 100644 --- a/backend/igny8_core/modules/system/utils.py +++ b/backend/igny8_core/modules/system/utils.py @@ -250,7 +250,7 @@ Return a JSON object with this structure: Make sure each prompt is detailed enough for image generation, describing the visual elements, style, mood, and composition.""", - 'image_prompt_template': 'Create a high-quality {image_type} image to use as a featured photo for a blog post titled "{post_title}". The image should visually represent the theme, mood, and subject implied by the image prompt: {image_prompt}. Focus on a realistic, well-composed scene that naturally communicates the topic without text or logos. Use balanced lighting, pleasing composition, and photographic detail suitable for lifestyle or editorial web content. Avoid adding any visible or readable text, brand names, or illustrative effects. **And make sure image is not blurry.**', + 'image_prompt_template': '{image_type} image for blog post titled "{post_title}": {image_prompt}', 'negative_prompt': 'text, watermark, logo, overlay, title, caption, writing on walls, writing on objects, UI, infographic elements, post title',