Files
igny8/backend/igny8_core/ai/settings.py
IGNY8 VPS (Salman) 6044fab57d Step 2: Remove MODEL_CONFIG and update get_model_config() to use IntegrationSettings only
- Remove MODEL_CONFIG dict with hardcoded defaults
- Update get_model_config() to require account parameter
- Remove default_config fallback
- Remove unused helper functions (get_model, get_max_tokens, get_temperature)
- Fix generate_images.py to pass account to get_model_config()
- Raise ValueError with clear messages when IntegrationSettings not configured
2025-11-16 09:17:17 +00:00

98 lines
3.2 KiB
Python

"""
AI Settings - Centralized model configurations and limits
Uses IntegrationSettings only - no hardcoded defaults or fallbacks.
"""
from typing import Dict, Any
import logging
logger = logging.getLogger(__name__)
# Function name aliases (for backward compatibility)
FUNCTION_ALIASES = {
"cluster_keywords": "auto_cluster",
"auto_cluster_keywords": "auto_cluster",
"auto_generate_ideas": "generate_ideas",
"auto_generate_content": "generate_content",
"auto_generate_images": "generate_images",
}
def get_model_config(function_name: str, account) -> Dict[str, Any]:
"""
Get model configuration from IntegrationSettings only.
No fallbacks - account must have IntegrationSettings configured.
Args:
function_name: Name of the AI function
account: Account instance (required)
Returns:
dict: Model configuration with 'model', 'max_tokens', 'temperature'
Raises:
ValueError: If account not provided or IntegrationSettings not configured
"""
if not account:
raise ValueError("Account is required for model configuration")
# Resolve function alias
actual_name = FUNCTION_ALIASES.get(function_name, function_name)
# Get IntegrationSettings for OpenAI
try:
from igny8_core.modules.system.models import IntegrationSettings
integration_settings = IntegrationSettings.objects.get(
integration_type='openai',
account=account,
is_active=True
)
except IntegrationSettings.DoesNotExist:
raise ValueError(
f"OpenAI IntegrationSettings not configured for account {account.id}. "
f"Please configure OpenAI settings in the integration page."
)
config = integration_settings.config or {}
# Get model from config
model = config.get('model')
if not model:
raise ValueError(
f"Model not configured in IntegrationSettings for account {account.id}. "
f"Please set 'model' in OpenAI integration settings."
)
# Validate model is in our supported list (optional validation)
try:
from igny8_core.utils.ai_processor import MODEL_RATES
if model not in MODEL_RATES:
logger.warning(
f"Model '{model}' for account {account.id} is not in supported list. "
f"Supported models: {list(MODEL_RATES.keys())}"
)
except ImportError:
# MODEL_RATES not available - skip validation
pass
# Get max_tokens and temperature from config (with reasonable defaults for API)
max_tokens = config.get('max_tokens', 4000) # Reasonable default for API limits
temperature = config.get('temperature', 0.7) # Reasonable default
# Build response format based on model (JSON mode for supported models)
response_format = None
try:
from igny8_core.ai.constants import JSON_MODE_MODELS
if model in JSON_MODE_MODELS:
response_format = {"type": "json_object"}
except ImportError:
# JSON_MODE_MODELS not available - skip
pass
return {
'model': model,
'max_tokens': max_tokens,
'temperature': temperature,
'response_format': response_format,
}