Revert image prompt changes - investigate original issue
This commit is contained in:
@@ -123,120 +123,3 @@ def get_model_config(function_name: str, account) -> Dict[str, Any]:
|
||||
'response_format': response_format,
|
||||
}
|
||||
|
||||
|
||||
def get_image_generation_config(account) -> Dict[str, Any]:
|
||||
"""
|
||||
Get image generation configuration for AI functions.
|
||||
|
||||
Architecture:
|
||||
- API keys: ALWAYS from GlobalIntegrationSettings (platform-wide)
|
||||
- Model/params: From IntegrationSettings if account has override, else from global
|
||||
- Supports both OpenAI (DALL-E) and Runware providers
|
||||
|
||||
Args:
|
||||
account: Account instance (required)
|
||||
|
||||
Returns:
|
||||
dict: Image generation configuration with 'provider', 'model', 'api_key',
|
||||
'size', 'quality', 'style', 'max_in_article_images'
|
||||
|
||||
Raises:
|
||||
ValueError: If account not provided or settings not configured
|
||||
"""
|
||||
if not account:
|
||||
raise ValueError("Account is required for image generation configuration")
|
||||
|
||||
try:
|
||||
from igny8_core.modules.system.global_settings_models import GlobalIntegrationSettings
|
||||
from igny8_core.modules.system.models import IntegrationSettings
|
||||
|
||||
# Get global settings (for API keys and defaults)
|
||||
global_settings = GlobalIntegrationSettings.get_instance()
|
||||
|
||||
# Start with global defaults
|
||||
provider = global_settings.default_image_service # 'openai' or 'runware'
|
||||
max_in_article_images = global_settings.max_in_article_images
|
||||
|
||||
if provider == 'runware':
|
||||
api_key = global_settings.runware_api_key
|
||||
model = global_settings.runware_model
|
||||
size = global_settings.desktop_image_size
|
||||
quality = global_settings.image_quality
|
||||
style = global_settings.image_style
|
||||
|
||||
if not api_key:
|
||||
raise ValueError(
|
||||
"Platform Runware API key not configured. "
|
||||
"Please configure GlobalIntegrationSettings in Django admin."
|
||||
)
|
||||
else: # openai/dalle
|
||||
api_key = global_settings.dalle_api_key or global_settings.openai_api_key
|
||||
model = global_settings.dalle_model
|
||||
size = global_settings.dalle_size
|
||||
quality = global_settings.image_quality
|
||||
style = global_settings.image_style
|
||||
|
||||
if not api_key:
|
||||
raise ValueError(
|
||||
"Platform OpenAI/DALL-E API key not configured. "
|
||||
"Please configure GlobalIntegrationSettings in Django admin."
|
||||
)
|
||||
|
||||
# Check if account has overrides
|
||||
# Try both 'image_generation' and provider-specific types for backward compatibility
|
||||
account_settings = None
|
||||
for integration_type in ['image_generation', provider, 'dalle', 'runware']:
|
||||
try:
|
||||
account_settings = IntegrationSettings.objects.get(
|
||||
account=account,
|
||||
integration_type=integration_type,
|
||||
is_active=True
|
||||
)
|
||||
break
|
||||
except IntegrationSettings.DoesNotExist:
|
||||
continue
|
||||
|
||||
if account_settings:
|
||||
config = account_settings.config or {}
|
||||
|
||||
# Override provider if specified
|
||||
if config.get('provider') or config.get('service'):
|
||||
provider = config.get('provider') or config.get('service')
|
||||
|
||||
# Override model if specified
|
||||
if config.get('model'):
|
||||
model = config['model']
|
||||
|
||||
# Override size if specified
|
||||
if config.get('size') or config.get('image_size'):
|
||||
size = config.get('size') or config.get('image_size')
|
||||
|
||||
# Override quality if specified
|
||||
if config.get('quality') or config.get('image_quality'):
|
||||
quality = config.get('quality') or config.get('image_quality')
|
||||
|
||||
# Override style if specified
|
||||
if config.get('style') or config.get('image_style'):
|
||||
style = config.get('style') or config.get('image_style')
|
||||
|
||||
# Override max_in_article_images if specified
|
||||
if config.get('max_in_article_images'):
|
||||
max_in_article_images = int(config['max_in_article_images'])
|
||||
|
||||
return {
|
||||
'provider': provider,
|
||||
'model': model,
|
||||
'api_key': api_key, # ALWAYS from global
|
||||
'size': size,
|
||||
'quality': quality,
|
||||
'style': style,
|
||||
'max_in_article_images': max_in_article_images,
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Could not load image generation settings for account {account.id}: {e}")
|
||||
raise ValueError(
|
||||
f"Could not load image generation configuration for account {account.id}. "
|
||||
f"Please configure GlobalIntegrationSettings."
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user