Spaces:
Paused
Paused
Commit ·
6e75c75
1
Parent(s): efb0b84
✅ Fix model addition confirmation and display issues
Browse files- Add 2-second delay before page reload to show success notification
- Enhance success notifications with checkmark emoji and longer duration
- Add synchronous Firebase save methods for critical model addition operations
- Ensure newly added models appear immediately in provider sections
- Improve notification styling with better visibility and shadows
- Add debug logging for successful model additions
This resolves the issues where:
1. Success confirmations weren't visible due to immediate page reload
2. Newly added models weren't appearing in the interface
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
pages/admin/model_families.html
CHANGED
|
@@ -626,29 +626,35 @@ function updateProviderStats(provider) {
|
|
| 626 |
function showNotification(message, type) {
|
| 627 |
const notification = document.createElement('div');
|
| 628 |
notification.className = `flash flash-${type}`;
|
| 629 |
-
notification.textContent = message;
|
| 630 |
notification.style.position = 'fixed';
|
| 631 |
notification.style.top = '20px';
|
| 632 |
notification.style.right = '20px';
|
| 633 |
notification.style.zIndex = '9999';
|
| 634 |
-
notification.style.padding = '
|
| 635 |
-
notification.style.borderRadius = '
|
| 636 |
notification.style.color = 'white';
|
| 637 |
-
notification.style.fontSize = '
|
|
|
|
|
|
|
| 638 |
|
| 639 |
if (type === 'success') {
|
| 640 |
notification.style.backgroundColor = '#28a745';
|
|
|
|
| 641 |
} else if (type === 'error') {
|
| 642 |
notification.style.backgroundColor = '#dc3545';
|
|
|
|
| 643 |
} else if (type === 'info') {
|
| 644 |
notification.style.backgroundColor = '#17a2b8';
|
|
|
|
| 645 |
}
|
| 646 |
|
| 647 |
document.body.appendChild(notification);
|
| 648 |
|
|
|
|
|
|
|
| 649 |
setTimeout(() => {
|
| 650 |
notification.remove();
|
| 651 |
-
},
|
| 652 |
}
|
| 653 |
|
| 654 |
function showModal(modalId) {
|
|
@@ -717,8 +723,10 @@ document.getElementById('addModelForm').addEventListener('submit', function(e) {
|
|
| 717 |
if (result.success) {
|
| 718 |
showNotification(result.message, 'success');
|
| 719 |
hideModal('addModelModal');
|
| 720 |
-
//
|
| 721 |
-
|
|
|
|
|
|
|
| 722 |
} else {
|
| 723 |
const errorDiv = document.getElementById('addModelErrors');
|
| 724 |
if (result.field_errors) {
|
|
|
|
| 626 |
function showNotification(message, type) {
|
| 627 |
const notification = document.createElement('div');
|
| 628 |
notification.className = `flash flash-${type}`;
|
|
|
|
| 629 |
notification.style.position = 'fixed';
|
| 630 |
notification.style.top = '20px';
|
| 631 |
notification.style.right = '20px';
|
| 632 |
notification.style.zIndex = '9999';
|
| 633 |
+
notification.style.padding = '15px 25px';
|
| 634 |
+
notification.style.borderRadius = '8px';
|
| 635 |
notification.style.color = 'white';
|
| 636 |
+
notification.style.fontSize = '16px';
|
| 637 |
+
notification.style.fontWeight = 'bold';
|
| 638 |
+
notification.style.boxShadow = '0 4px 12px rgba(0,0,0,0.3)';
|
| 639 |
|
| 640 |
if (type === 'success') {
|
| 641 |
notification.style.backgroundColor = '#28a745';
|
| 642 |
+
notification.innerHTML = '✅ ' + message;
|
| 643 |
} else if (type === 'error') {
|
| 644 |
notification.style.backgroundColor = '#dc3545';
|
| 645 |
+
notification.innerHTML = '❌ ' + message;
|
| 646 |
} else if (type === 'info') {
|
| 647 |
notification.style.backgroundColor = '#17a2b8';
|
| 648 |
+
notification.innerHTML = 'ℹ️ ' + message;
|
| 649 |
}
|
| 650 |
|
| 651 |
document.body.appendChild(notification);
|
| 652 |
|
| 653 |
+
// Success messages show longer
|
| 654 |
+
const duration = type === 'success' ? 5000 : 3000;
|
| 655 |
setTimeout(() => {
|
| 656 |
notification.remove();
|
| 657 |
+
}, duration);
|
| 658 |
}
|
| 659 |
|
| 660 |
function showModal(modalId) {
|
|
|
|
| 723 |
if (result.success) {
|
| 724 |
showNotification(result.message, 'success');
|
| 725 |
hideModal('addModelModal');
|
| 726 |
+
// Show success message for 2 seconds before refresh
|
| 727 |
+
setTimeout(() => {
|
| 728 |
+
location.reload();
|
| 729 |
+
}, 2000);
|
| 730 |
} else {
|
| 731 |
const errorDiv = document.getElementById('addModelErrors');
|
| 732 |
if (result.field_errors) {
|
src/services/model_families.py
CHANGED
|
@@ -370,6 +370,30 @@ class ModelFamilyManager:
|
|
| 370 |
except Exception as e:
|
| 371 |
print(f"Failed to save model families to file: {e}")
|
| 372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
def is_model_whitelisted(self, provider: AIProvider, model_id: str) -> bool:
|
| 374 |
"""Check if a model is whitelisted for use"""
|
| 375 |
with self.lock:
|
|
@@ -545,7 +569,7 @@ class ModelFamilyManager:
|
|
| 545 |
if model_info.model_id in self.models:
|
| 546 |
return False
|
| 547 |
|
| 548 |
-
# Add the model
|
| 549 |
self.models[model_info.model_id] = model_info
|
| 550 |
|
| 551 |
# Auto-whitelist if requested
|
|
@@ -555,12 +579,13 @@ class ModelFamilyManager:
|
|
| 555 |
self.whitelisted_models[provider] = set()
|
| 556 |
self.whitelisted_models[provider].add(model_info.model_id)
|
| 557 |
|
| 558 |
-
# Save configuration
|
| 559 |
-
self.
|
| 560 |
|
| 561 |
-
# Save custom models to Firebase/file
|
| 562 |
-
self.
|
| 563 |
|
|
|
|
| 564 |
return True
|
| 565 |
|
| 566 |
def remove_custom_model(self, model_id: str) -> bool:
|
|
@@ -673,6 +698,36 @@ class ModelFamilyManager:
|
|
| 673 |
except Exception as e:
|
| 674 |
print(f"Failed to save custom models to file: {e}")
|
| 675 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 676 |
def _load_custom_models(self):
|
| 677 |
"""Load custom models from persistent storage"""
|
| 678 |
if self.firebase_db:
|
|
|
|
| 370 |
except Exception as e:
|
| 371 |
print(f"Failed to save model families to file: {e}")
|
| 372 |
|
| 373 |
+
def _save_configuration_sync(self):
|
| 374 |
+
"""Save configuration synchronously (for critical operations like model addition)"""
|
| 375 |
+
config = {
|
| 376 |
+
'whitelisted_models': {
|
| 377 |
+
provider.value: list(models)
|
| 378 |
+
for provider, models in self.whitelisted_models.items()
|
| 379 |
+
},
|
| 380 |
+
'last_updated': datetime.now().isoformat()
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
if self.firebase_db:
|
| 384 |
+
try:
|
| 385 |
+
config_ref = self.firebase_db.child('model_families_config')
|
| 386 |
+
config_ref.set(config)
|
| 387 |
+
print("Saved model families config to Firebase (sync)")
|
| 388 |
+
except Exception as e:
|
| 389 |
+
print(f"Failed to save model families to Firebase (sync): {e}")
|
| 390 |
+
else:
|
| 391 |
+
try:
|
| 392 |
+
with open("model_families_config.json", 'w') as f:
|
| 393 |
+
json.dump(config, f, indent=2)
|
| 394 |
+
except Exception as e:
|
| 395 |
+
print(f"Failed to save model families to file: {e}")
|
| 396 |
+
|
| 397 |
def is_model_whitelisted(self, provider: AIProvider, model_id: str) -> bool:
|
| 398 |
"""Check if a model is whitelisted for use"""
|
| 399 |
with self.lock:
|
|
|
|
| 569 |
if model_info.model_id in self.models:
|
| 570 |
return False
|
| 571 |
|
| 572 |
+
# Add the model to in-memory storage first
|
| 573 |
self.models[model_info.model_id] = model_info
|
| 574 |
|
| 575 |
# Auto-whitelist if requested
|
|
|
|
| 579 |
self.whitelisted_models[provider] = set()
|
| 580 |
self.whitelisted_models[provider].add(model_info.model_id)
|
| 581 |
|
| 582 |
+
# Save configuration (this ensures immediate persistence)
|
| 583 |
+
self._save_configuration_sync()
|
| 584 |
|
| 585 |
+
# Save custom models to Firebase/file
|
| 586 |
+
self._save_custom_models_sync()
|
| 587 |
|
| 588 |
+
print(f"Successfully added custom model: {model_info.model_id} to provider {model_info.provider.value}")
|
| 589 |
return True
|
| 590 |
|
| 591 |
def remove_custom_model(self, model_id: str) -> bool:
|
|
|
|
| 698 |
except Exception as e:
|
| 699 |
print(f"Failed to save custom models to file: {e}")
|
| 700 |
|
| 701 |
+
def _save_custom_models_sync(self):
|
| 702 |
+
"""Save custom models synchronously (for critical operations like model addition)"""
|
| 703 |
+
custom_models = self.get_custom_models()
|
| 704 |
+
|
| 705 |
+
# Convert to serializable format
|
| 706 |
+
models_data = []
|
| 707 |
+
for model in custom_models:
|
| 708 |
+
model_dict = asdict(model)
|
| 709 |
+
model_dict['provider'] = model.provider.value # Convert enum to string
|
| 710 |
+
models_data.append(model_dict)
|
| 711 |
+
|
| 712 |
+
config = {
|
| 713 |
+
'custom_models': models_data,
|
| 714 |
+
'last_updated': datetime.now().isoformat()
|
| 715 |
+
}
|
| 716 |
+
|
| 717 |
+
if self.firebase_db:
|
| 718 |
+
try:
|
| 719 |
+
custom_models_ref = self.firebase_db.child('custom_models')
|
| 720 |
+
custom_models_ref.set(config)
|
| 721 |
+
print("Saved custom models to Firebase (sync)")
|
| 722 |
+
except Exception as e:
|
| 723 |
+
print(f"Failed to save custom models to Firebase (sync): {e}")
|
| 724 |
+
else:
|
| 725 |
+
try:
|
| 726 |
+
with open("custom_models.json", 'w') as f:
|
| 727 |
+
json.dump(config, f, indent=2)
|
| 728 |
+
except Exception as e:
|
| 729 |
+
print(f"Failed to save custom models to file: {e}")
|
| 730 |
+
|
| 731 |
def _load_custom_models(self):
|
| 732 |
"""Load custom models from persistent storage"""
|
| 733 |
if self.firebase_db:
|