kokofixcomputers commited on
Commit
c271e98
·
verified ·
1 Parent(s): 9e4f513

undefined - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +63 -13
index.html CHANGED
@@ -620,6 +620,22 @@
620
  defaultChatSettings = JSON.parse(savedDefaults);
621
  }
622
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
623
  // Load custom providers
624
  customProviders.forEach(provider => {
625
  models.push({
@@ -851,6 +867,12 @@
851
  function renderCustomModels() {
852
  customModelsList.innerHTML = '';
853
 
 
 
 
 
 
 
854
  if (customModels.length === 0) {
855
  customModelsList.innerHTML = `
856
  <div class="text-center text-gray-500 dark:text-gray-400 py-2 text-sm">
@@ -1085,7 +1107,7 @@
1085
  }
1086
 
1087
  // Get current chat
1088
- const chatIndex = chats.findIndex(c => c.id === currentChatId);
1089
  if (chatIndex === -1) return;
1090
 
1091
  const chat = chats[chatIndex];
@@ -1104,17 +1126,27 @@
1104
  timestamp: new Date().toISOString()
1105
  };
1106
 
1107
- chat.messages.push(userMessage);
1108
- chat.lastMessage = message.length > 30 ? message.substring(0, 30) + '...' : message;
 
 
 
 
 
1109
 
1110
- // Update UI
 
 
 
 
1111
  renderMessages(chat.messages);
1112
  messageInput.value = '';
 
1113
 
1114
  // Create assistant message element for streaming/response
1115
- const messageElement = document.createElement('div');
1116
- messageElement.className = 'flex gap-4 justify-start';
1117
- messageElement.innerHTML = `
1118
  <div class="flex-shrink-0 w-8 h-8 rounded-full bg-primary-500 text-white flex items-center justify-center">
1119
  <i class="fas fa-robot"></i>
1120
  </div>
@@ -1127,15 +1159,15 @@
1127
  <div class="prose dark:prose-invert hidden" id="streaming-content"></div>
1128
  </div>
1129
  `;
1130
- chatArea.appendChild(messageElement);
1131
- const contentElement = messageElement.querySelector('#streaming-content');
1132
- const loadingIndicator = messageElement.querySelector('#loading-indicator');
1133
 
1134
  try {
1135
  // Ensure we have the latest chat reference first
1136
- let chatIndex = chats.findIndex(c => c.id === currentChatId);
1137
  if (chatIndex === -1) throw new Error('Chat not found');
1138
- let currentChat = chats[chatIndex];
1139
 
1140
  // Get the current model
1141
  const model = models.find(m => m.id === currentChat.model);
@@ -1184,7 +1216,7 @@
1184
  };
1185
 
1186
  // Replace the last message (which was the loading one) with the actual response
1187
- currentChat.messages[currentChat.messages.length - 1] = assistantMessage;
1188
  saveChats();
1189
 
1190
  // Update chat list
@@ -1476,6 +1508,24 @@
1476
 
1477
  // Select model
1478
  function selectModel(modelId) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1479
  const model = models.find(m => m.id === modelId);
1480
  if (!model) return;
1481
 
 
620
  defaultChatSettings = JSON.parse(savedDefaults);
621
  }
622
 
623
+ // Load custom models from localStorage
624
+ const savedCustomModels = localStorage.getItem('customModels');
625
+ if (savedCustomModels) {
626
+ customModels = JSON.parse(savedCustomModels);
627
+ customModels.forEach(model => {
628
+ models.push({
629
+ id: model.id,
630
+ name: model.name,
631
+ endpoint: model.endpoint,
632
+ key: model.key,
633
+ streaming: model.streaming || false,
634
+ type: 'custom'
635
+ });
636
+ });
637
+ }
638
+
639
  // Load custom providers
640
  customProviders.forEach(provider => {
641
  models.push({
 
867
  function renderCustomModels() {
868
  customModelsList.innerHTML = '';
869
 
870
+ // Reload custom models from localStorage to ensure we have latest
871
+ const savedCustomModels = localStorage.getItem('customModels');
872
+ if (savedCustomModels) {
873
+ customModels = JSON.parse(savedCustomModels);
874
+ }
875
+
876
  if (customModels.length === 0) {
877
  customModelsList.innerHTML = `
878
  <div class="text-center text-gray-500 dark:text-gray-400 py-2 text-sm">
 
1107
  }
1108
 
1109
  // Get current chat
1110
+ let chatIndex = chats.findIndex(c => c.id === currentChatId);
1111
  if (chatIndex === -1) return;
1112
 
1113
  const chat = chats[chatIndex];
 
1126
  timestamp: new Date().toISOString()
1127
  };
1128
 
1129
+ // Ensure we have the latest chat reference
1130
+ chatIndex = chats.findIndex(c => c.id === currentChatId);
1131
+ if (chatIndex === -1) return;
1132
+ let currentChat = chats[chatIndex];
1133
+
1134
+ currentChat.messages.push(userMessage);
1135
+ currentChat.lastMessage = message.length > 30 ? message.substring(0, 30) + '...' : message;
1136
 
1137
+ // Save chat immediately after adding user message
1138
+ chats[chatIndex] = currentChat;
1139
+ saveChats();
1140
+
1141
+ // Render all messages including the new user message
1142
  renderMessages(chat.messages);
1143
  messageInput.value = '';
1144
+ chatArea.scrollTop = chatArea.scrollHeight;
1145
 
1146
  // Create assistant message element for streaming/response
1147
+ const assistantMessageElement = document.createElement('div');
1148
+ assistantMessageElement.className = 'flex gap-4 justify-start';
1149
+ assistantMessageElement.innerHTML = `
1150
  <div class="flex-shrink-0 w-8 h-8 rounded-full bg-primary-500 text-white flex items-center justify-center">
1151
  <i class="fas fa-robot"></i>
1152
  </div>
 
1159
  <div class="prose dark:prose-invert hidden" id="streaming-content"></div>
1160
  </div>
1161
  `;
1162
+ chatArea.appendChild(assistantMessageElement);
1163
+ const contentElement = assistantMessageElement.querySelector('#streaming-content');
1164
+ const loadingIndicator = assistantMessageElement.querySelector('#loading-indicator');
1165
 
1166
  try {
1167
  // Ensure we have the latest chat reference first
1168
+ chatIndex = chats.findIndex(c => c.id === currentChatId);
1169
  if (chatIndex === -1) throw new Error('Chat not found');
1170
+ currentChat = chats[chatIndex];
1171
 
1172
  // Get the current model
1173
  const model = models.find(m => m.id === currentChat.model);
 
1216
  };
1217
 
1218
  // Replace the last message (which was the loading one) with the actual response
1219
+ currentChat.messages.push(assistantMessage);
1220
  saveChats();
1221
 
1222
  // Update chat list
 
1508
 
1509
  // Select model
1510
  function selectModel(modelId) {
1511
+ // Ensure models array is up to date
1512
+ const savedCustomModels = localStorage.getItem('customModels');
1513
+ if (savedCustomModels) {
1514
+ customModels = JSON.parse(savedCustomModels);
1515
+ // Update models array with latest custom models
1516
+ models = models.filter(m => m.type !== 'custom');
1517
+ customModels.forEach(model => {
1518
+ models.push({
1519
+ id: model.id,
1520
+ name: model.name,
1521
+ endpoint: model.endpoint,
1522
+ key: model.key,
1523
+ streaming: model.streaming || false,
1524
+ type: 'custom'
1525
+ });
1526
+ });
1527
+ }
1528
+
1529
  const model = models.find(m => m.id === modelId);
1530
  if (!model) return;
1531