Enhance AICore model validation and logging
- Improved model configuration handling in AICore to ensure only supported models are set as default. - Added error logging for invalid model configurations and warnings for missing models. - Implemented validation checks for the active model to provide clear error messages when no valid model is configured. - Enhanced user feedback during AI model selection to improve debugging and configuration clarity.
This commit is contained in:
@@ -58,8 +58,17 @@ class AICore:
|
||||
if openai_settings and openai_settings.config:
|
||||
self._openai_api_key = openai_settings.config.get('apiKey')
|
||||
model = openai_settings.config.get('model')
|
||||
if model and model in MODEL_RATES:
|
||||
self._default_model = model
|
||||
if model:
|
||||
if model in MODEL_RATES:
|
||||
self._default_model = model
|
||||
logger.info(f"Loaded model '{model}' from IntegrationSettings for account {self.account.id}")
|
||||
else:
|
||||
error_msg = f"Model '{model}' from IntegrationSettings is not in supported models list. Supported models: {list(MODEL_RATES.keys())}"
|
||||
logger.error(f"[AICore] {error_msg}")
|
||||
logger.error(f"[AICore] Account {self.account.id} has invalid model configuration. Please update Integration Settings.")
|
||||
# Don't set _default_model, will fall back to Django settings
|
||||
else:
|
||||
logger.warning(f"No model configured in IntegrationSettings for account {self.account.id}, will use fallback")
|
||||
|
||||
# Load Runware settings
|
||||
runware_settings = IntegrationSettings.objects.filter(
|
||||
@@ -148,6 +157,38 @@ class AICore:
|
||||
|
||||
# Step 2: Determine model
|
||||
active_model = model or self._default_model
|
||||
|
||||
# Validate model is available and supported
|
||||
if not active_model:
|
||||
error_msg = 'No AI model configured. Please configure a model in Integration Settings or Django settings.'
|
||||
logger.error(f"[AICore] {error_msg}")
|
||||
tracker.error('ConfigurationError', error_msg)
|
||||
return {
|
||||
'content': None,
|
||||
'error': error_msg,
|
||||
'input_tokens': 0,
|
||||
'output_tokens': 0,
|
||||
'total_tokens': 0,
|
||||
'model': None,
|
||||
'cost': 0.0,
|
||||
'api_id': None,
|
||||
}
|
||||
|
||||
if active_model not in MODEL_RATES:
|
||||
error_msg = f"Model '{active_model}' is not supported. Supported models: {list(MODEL_RATES.keys())}"
|
||||
logger.error(f"[AICore] {error_msg}")
|
||||
tracker.error('ConfigurationError', error_msg)
|
||||
return {
|
||||
'content': None,
|
||||
'error': error_msg,
|
||||
'input_tokens': 0,
|
||||
'output_tokens': 0,
|
||||
'total_tokens': 0,
|
||||
'model': active_model,
|
||||
'cost': 0.0,
|
||||
'api_id': None,
|
||||
}
|
||||
|
||||
tracker.ai_call(f"Using model: {active_model}")
|
||||
|
||||
# Step 3: Auto-enable JSON mode for supported models
|
||||
|
||||
Reference in New Issue
Block a user