This commit is contained in:
Desktop
2025-11-10 20:05:05 +05:00
parent 9be2523e36
commit d17d87a375
4 changed files with 109 additions and 6 deletions

View File

@@ -46,12 +46,14 @@ FUNCTION_ALIASES = {
}
def get_model_config(function_name: str) -> Dict[str, Any]:
def get_model_config(function_name: str, account=None) -> Dict[str, Any]:
"""
Get model configuration for an AI function.
Reads model from IntegrationSettings if account is provided, otherwise uses defaults.
Args:
function_name: AI function name (e.g., 'auto_cluster', 'generate_ideas')
account: Optional account object to read model from IntegrationSettings
Returns:
Dict with model, max_tokens, temperature, etc.
@@ -59,8 +61,30 @@ def get_model_config(function_name: str) -> Dict[str, Any]:
# Check aliases first
actual_name = FUNCTION_ALIASES.get(function_name, function_name)
# Get config or return defaults
config = MODEL_CONFIG.get(actual_name, {})
# Get base config
config = MODEL_CONFIG.get(actual_name, {}).copy()
# Try to get model from IntegrationSettings if account is provided
model_from_settings = None
if account:
try:
from igny8_core.modules.system.models import IntegrationSettings
openai_settings = IntegrationSettings.objects.filter(
integration_type='openai',
account=account,
is_active=True
).first()
if openai_settings and openai_settings.config:
model_from_settings = openai_settings.config.get('model')
if model_from_settings:
# Validate model is in our supported list
from igny8_core.utils.ai_processor import MODEL_RATES
if model_from_settings in MODEL_RATES:
config['model'] = model_from_settings
except Exception as e:
import logging
logger = logging.getLogger(__name__)
logger.warning(f"Could not load model from IntegrationSettings: {e}", exc_info=True)
# Merge with defaults
default_config = {