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())
|
self.tracker.update("PREP", 25, prep_message, meta=self.step_tracker.get_meta())
|
||||||
|
|
||||||
# Phase 3: AI_CALL - Provider API Call (25-70%)
|
# 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)
|
ai_core = AICore(account=self.account)
|
||||||
function_name = fn.get_name()
|
function_name = fn.get_name()
|
||||||
|
|
||||||
@@ -201,29 +207,21 @@ class AIEngine:
|
|||||||
function_id_base = function_name.replace('_', '-')
|
function_id_base = function_name.replace('_', '-')
|
||||||
function_id = f"ai-{function_id_base}-01-desktop"
|
function_id = f"ai-{function_id_base}-01-desktop"
|
||||||
|
|
||||||
# Get model config from settings (Stage 4 requirement)
|
# Get model config from settings (requires account)
|
||||||
# Pass account to read model from IntegrationSettings
|
# This will raise ValueError if IntegrationSettings not configured
|
||||||
model_config = get_model_config(function_name, account=self.account)
|
try:
|
||||||
model = model_config.get('model')
|
model_config = get_model_config(function_name, account=self.account)
|
||||||
|
model = model_config.get('model')
|
||||||
# Read model straight from IntegrationSettings for visibility
|
except ValueError as e:
|
||||||
model_from_integration = None
|
# IntegrationSettings not configured or model missing
|
||||||
if self.account:
|
error_msg = str(e)
|
||||||
try:
|
logger.error(f"[AIEngine] {error_msg}")
|
||||||
from igny8_core.modules.system.models import IntegrationSettings
|
return self._handle_error(error_msg, fn)
|
||||||
openai_settings = IntegrationSettings.objects.filter(
|
except Exception as e:
|
||||||
integration_type='openai',
|
# Other unexpected errors
|
||||||
account=self.account,
|
error_msg = f"Failed to get model configuration: {str(e)}"
|
||||||
is_active=True
|
logger.error(f"[AIEngine] {error_msg}", exc_info=True)
|
||||||
).first()
|
return self._handle_error(error_msg, fn)
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Debug logging: Show model configuration (console only, not in step tracker)
|
# Debug logging: Show model configuration (console only, not in step tracker)
|
||||||
logger.info(f"[AIEngine] Model Configuration for {function_name}:")
|
logger.info(f"[AIEngine] Model Configuration for {function_name}:")
|
||||||
|
|||||||
Reference in New Issue
Block a user