Step 4: Validate account exists before calling get_model_config() in engine.py
- Add account validation before calling get_model_config() - Wrap get_model_config() in try/except to handle ValueError (IntegrationSettings not configured) - Handle other unexpected errors from get_model_config() - Return proper error messages through _handle_error() - Remove redundant model_from_integration code (get_model_config already handles this)
This commit is contained in:
@@ -193,6 +193,12 @@ class AIEngine:
|
||||
self.tracker.update("PREP", 25, prep_message, meta=self.step_tracker.get_meta())
|
||||
|
||||
# Phase 3: AI_CALL - Provider API Call (25-70%)
|
||||
# Validate account exists before proceeding
|
||||
if not self.account:
|
||||
error_msg = "Account is required for AI function execution"
|
||||
logger.error(f"[AIEngine] {error_msg}")
|
||||
return self._handle_error(error_msg, fn)
|
||||
|
||||
ai_core = AICore(account=self.account)
|
||||
function_name = fn.get_name()
|
||||
|
||||
@@ -201,29 +207,21 @@ class AIEngine:
|
||||
function_id_base = function_name.replace('_', '-')
|
||||
function_id = f"ai-{function_id_base}-01-desktop"
|
||||
|
||||
# Get model config from settings (Stage 4 requirement)
|
||||
# Pass account to read model from IntegrationSettings
|
||||
model_config = get_model_config(function_name, account=self.account)
|
||||
model = model_config.get('model')
|
||||
|
||||
# Read model straight from IntegrationSettings for visibility
|
||||
model_from_integration = None
|
||||
if self.account:
|
||||
try:
|
||||
from igny8_core.modules.system.models import IntegrationSettings
|
||||
openai_settings = IntegrationSettings.objects.filter(
|
||||
integration_type='openai',
|
||||
account=self.account,
|
||||
is_active=True
|
||||
).first()
|
||||
if openai_settings and openai_settings.config:
|
||||
model_from_integration = openai_settings.config.get('model')
|
||||
except Exception as integration_error:
|
||||
logger.warning(
|
||||
"[AIEngine] Unable to read model from IntegrationSettings: %s",
|
||||
integration_error,
|
||||
exc_info=True,
|
||||
)
|
||||
# Get model config from settings (requires account)
|
||||
# This will raise ValueError if IntegrationSettings not configured
|
||||
try:
|
||||
model_config = get_model_config(function_name, account=self.account)
|
||||
model = model_config.get('model')
|
||||
except ValueError as e:
|
||||
# IntegrationSettings not configured or model missing
|
||||
error_msg = str(e)
|
||||
logger.error(f"[AIEngine] {error_msg}")
|
||||
return self._handle_error(error_msg, fn)
|
||||
except Exception as e:
|
||||
# Other unexpected errors
|
||||
error_msg = f"Failed to get model configuration: {str(e)}"
|
||||
logger.error(f"[AIEngine] {error_msg}", exc_info=True)
|
||||
return self._handle_error(error_msg, fn)
|
||||
|
||||
# Debug logging: Show model configuration (console only, not in step tracker)
|
||||
logger.info(f"[AIEngine] Model Configuration for {function_name}:")
|
||||
|
||||
Reference in New Issue
Block a user