kokofixcomputers commited on
Commit
b1c9fe4
·
verified ·
1 Parent(s): 1cfe365

add the ability to edit custom models - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +71 -4
index.html CHANGED
@@ -214,6 +214,7 @@
214
  <label for="modelKey" class="block text-sm font-medium mb-1">API Key (optional)</label>
215
  <input type="password" id="modelKey" class="w-full p-2 border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 focus:ring-primary-500 focus:border-primary-500" placeholder="sk-...">
216
  </div>
 
217
 
218
  <div class="flex justify-end gap-2">
219
  <button type="button" id="cancelAddModel" class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 transition-all">
@@ -413,9 +414,14 @@
413
 
414
  modelElement.innerHTML = `
415
  <span>${model.name}</span>
416
- <button class="delete-model text-gray-400 hover:text-red-500 transition-all p-1">
417
- <i class="fas fa-trash text-xs"></i>
418
- </button>
 
 
 
 
 
419
  `;
420
 
421
  modelElement.addEventListener('click', (e) => {
@@ -429,6 +435,12 @@
429
  e.stopPropagation();
430
  deleteCustomModel(model.id);
431
  });
 
 
 
 
 
 
432
 
433
  customModelsList.appendChild(modelElement);
434
  });
@@ -708,6 +720,37 @@
708
  hideAddModelModal();
709
  }
710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711
  // Delete custom model
712
  function deleteCustomModel(modelId) {
713
  customModels = customModels.filter(m => m.id !== modelId);
@@ -757,10 +800,28 @@
757
  addModelModal.classList.remove('hidden');
758
  }
759
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
760
  // Hide add model modal
761
  function hideAddModelModal() {
762
  addModelModal.classList.add('hidden');
763
  addModelForm.reset();
 
 
 
 
764
  }
765
 
766
  // Save chats to localStorage
@@ -888,7 +949,13 @@
888
  const name = document.getElementById('modelName').value;
889
  const endpoint = document.getElementById('modelEndpoint').value;
890
  const key = document.getElementById('modelKey').value;
891
- addCustomModel(name, endpoint, key);
 
 
 
 
 
 
892
  });
893
 
894
  // Delete chat
 
214
  <label for="modelKey" class="block text-sm font-medium mb-1">API Key (optional)</label>
215
  <input type="password" id="modelKey" class="w-full p-2 border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 focus:ring-primary-500 focus:border-primary-500" placeholder="sk-...">
216
  </div>
217
+ <input type="hidden" id="editModelId" value="">
218
 
219
  <div class="flex justify-end gap-2">
220
  <button type="button" id="cancelAddModel" class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded hover:bg-gray-100 dark:hover:bg-gray-700 transition-all">
 
414
 
415
  modelElement.innerHTML = `
416
  <span>${model.name}</span>
417
+ <div class="flex gap-1">
418
+ <button class="edit-model text-gray-400 hover:text-blue-500 transition-all p-1">
419
+ <i class="fas fa-edit text-xs"></i>
420
+ </button>
421
+ <button class="delete-model text-gray-400 hover:text-red-500 transition-all p-1">
422
+ <i class="fas fa-trash text-xs"></i>
423
+ </button>
424
+ </div>
425
  `;
426
 
427
  modelElement.addEventListener('click', (e) => {
 
435
  e.stopPropagation();
436
  deleteCustomModel(model.id);
437
  });
438
+
439
+ const editBtn = modelElement.querySelector('.edit-model');
440
+ editBtn.addEventListener('click', (e) => {
441
+ e.stopPropagation();
442
+ showEditModelModal(model);
443
+ });
444
 
445
  customModelsList.appendChild(modelElement);
446
  });
 
720
  hideAddModelModal();
721
  }
722
 
723
+ // Edit custom model
724
+ function editCustomModel(modelId, name, endpoint, key) {
725
+ const modelIndex = customModels.findIndex(m => m.id === modelId);
726
+ if (modelIndex === -1) return;
727
+
728
+ customModels[modelIndex] = {
729
+ ...customModels[modelIndex],
730
+ name,
731
+ endpoint,
732
+ key
733
+ };
734
+
735
+ // Update in models array
736
+ const globalModelIndex = models.findIndex(m => m.id === modelId);
737
+ if (globalModelIndex !== -1) {
738
+ models[globalModelIndex] = {
739
+ ...models[globalModelIndex],
740
+ name,
741
+ endpoint,
742
+ key
743
+ };
744
+ }
745
+
746
+ // Save to localStorage
747
+ localStorage.setItem('customModels', JSON.stringify(customModels));
748
+
749
+ // Update UI
750
+ renderCustomModels();
751
+ hideAddModelModal();
752
+ }
753
+
754
  // Delete custom model
755
  function deleteCustomModel(modelId) {
756
  customModels = customModels.filter(m => m.id !== modelId);
 
800
  addModelModal.classList.remove('hidden');
801
  }
802
 
803
+ // Show edit model modal
804
+ function showEditModelModal(model) {
805
+ document.getElementById('modelName').value = model.name;
806
+ document.getElementById('modelEndpoint').value = model.endpoint;
807
+ document.getElementById('modelKey').value = model.key || '';
808
+ document.getElementById('editModelId').value = model.id;
809
+
810
+ // Change modal title and submit button text
811
+ document.querySelector('#addModelModal h3').textContent = 'Edit Custom Model';
812
+ document.querySelector('#addModelForm button[type="submit"]').textContent = 'Save Changes';
813
+
814
+ showAddModelModal();
815
+ }
816
+
817
  // Hide add model modal
818
  function hideAddModelModal() {
819
  addModelModal.classList.add('hidden');
820
  addModelForm.reset();
821
+
822
+ // Reset modal title and submit button text
823
+ document.querySelector('#addModelModal h3').textContent = 'Add Custom Model';
824
+ document.querySelector('#addModelForm button[type="submit"]').textContent = 'Add Model';
825
  }
826
 
827
  // Save chats to localStorage
 
949
  const name = document.getElementById('modelName').value;
950
  const endpoint = document.getElementById('modelEndpoint').value;
951
  const key = document.getElementById('modelKey').value;
952
+ const editModelId = document.getElementById('editModelId').value;
953
+
954
+ if (editModelId) {
955
+ editCustomModel(editModelId, name, endpoint, key);
956
+ } else {
957
+ addCustomModel(name, endpoint, key);
958
+ }
959
  });
960
 
961
  // Delete chat