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:
Desktop
2025-11-10 20:18:19 +05:00
parent d17d87a375
commit 4277c93e44
2 changed files with 94 additions and 53 deletions

View File

@@ -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

View File

@@ -232,6 +232,57 @@ export function useProgressModal(): UseProgressModalReturn {
`/v1/system/settings/task_progress/${taskId}/`
);
// Helper function to start auto-increment progress (1% every 300ms until 80%)
const startAutoIncrement = () => {
// Clear any existing auto-increment interval
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
// Only start if we're below 80%
if (displayedPercentageRef.current < 80) {
autoIncrementIntervalRef.current = setInterval(() => {
setProgress(prev => {
// Check current status - stop if not processing
if (prev.status !== 'processing') {
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
return prev;
}
const current = displayedPercentageRef.current;
if (current < 80) {
const newPercentage = Math.min(current + 1, 80);
displayedPercentageRef.current = newPercentage;
// Stop if we've reached 80%
if (newPercentage >= 80) {
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
}
return {
...prev,
percentage: newPercentage,
};
} else {
// Stop if we've reached 80%
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
return prev;
}
});
}, 300);
}
};
if (response.state === 'PROGRESS') {
const meta = response.meta || {};
@@ -404,57 +455,6 @@ export function useProgressModal(): UseProgressModalReturn {
startAutoIncrement();
}
// Helper function to start auto-increment progress (1% every 300ms until 80%)
const startAutoIncrement = () => {
// Clear any existing auto-increment interval
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
// Only start if we're below 80%
if (displayedPercentageRef.current < 80) {
autoIncrementIntervalRef.current = setInterval(() => {
setProgress(prev => {
// Check current status - stop if not processing
if (prev.status !== 'processing') {
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
return prev;
}
const current = displayedPercentageRef.current;
if (current < 80) {
const newPercentage = Math.min(current + 1, 80);
displayedPercentageRef.current = newPercentage;
// Stop if we've reached 80%
if (newPercentage >= 80) {
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
}
return {
...prev,
percentage: newPercentage,
};
} else {
// Stop if we've reached 80%
if (autoIncrementIntervalRef.current) {
clearInterval(autoIncrementIntervalRef.current);
autoIncrementIntervalRef.current = null;
}
return prev;
}
});
}, 300);
}
};
// Update step logs if available
if (meta.request_steps || meta.response_steps) {
// Collect all steps for display in modal