12
This commit is contained in:
@@ -88,7 +88,8 @@ class AIEngine:
|
||||
function_id = f"ai-{function_id_base}-01-desktop"
|
||||
|
||||
# Get model config from settings (Stage 4 requirement)
|
||||
model_config = get_model_config(function_name)
|
||||
# Pass account to read model from IntegrationSettings
|
||||
model_config = get_model_config(function_name, account=self.account)
|
||||
model = model_config.get('model')
|
||||
|
||||
self.console_tracker.ai_call(f"Calling {model or 'default'} model with {len(prompt)} char prompt")
|
||||
|
||||
@@ -279,8 +279,8 @@ def generate_ideas_core(cluster_id: int, account_id: int = None, progress_callba
|
||||
tracker.prep("Building prompt...")
|
||||
prompt = fn.build_prompt(data, account)
|
||||
|
||||
# Get model config from settings
|
||||
model_config = get_model_config('generate_ideas')
|
||||
# Get model config from settings (pass account to read from IntegrationSettings)
|
||||
model_config = get_model_config('generate_ideas', account=account)
|
||||
|
||||
# Generate function_id for tracking (ai-generate-ideas-02 for legacy path)
|
||||
function_id = "ai-generate-ideas-02-desktop"
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user