Fix character attachment content saving into settings.json
| @@ -1,3 +1,4 @@ | ||
| 1 | +import { event_types, eventSource, saveSettingsDebounced } from '../../../script.js'; | |
| 1 | 2 | import { deleteAttachment, getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment, uploadFileAttachmentToServer } from '../../chats.js'; |
| 2 | 3 | import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 3 | 4 | import { SlashCommand } from '../../slash-commands/SlashCommand.js'; |
| @@ -196,7 +197,27 @@ async function enableDataBankAttachment(args, value) { | ||
| 196 | 197 | return ''; |
| 197 | 198 | } |
| 198 | 199 | |
| 200 | +function cleanUpAttachments() { | |
| 201 | + let shouldSaveSettings = false; | |
| 202 | + if (extension_settings.character_attachments) { | |
| 203 | + Object.values(extension_settings.character_attachments).flat().filter(a => a.text).forEach(a => { | |
| 204 | + shouldSaveSettings = true; | |
| 205 | + delete a.text; | |
| 206 | + }); | |
| 207 | + } | |
| 208 | + if (Array.isArray(extension_settings.attachments)) { | |
| 209 | + extension_settings.attachments.filter(a => a.text).forEach(a => { | |
| 210 | + shouldSaveSettings = true; | |
| 211 | + delete a.text; | |
| 212 | + }); | |
| 213 | + } | |
| 214 | + if (shouldSaveSettings) { | |
| 215 | + saveSettingsDebounced(); | |
| 216 | + } | |
| 217 | +} | |
| 218 | + | |
| 199 | 219 | jQuery(async () => { |
| 220 | + eventSource.on(event_types.APP_READY, cleanUpAttachments); | |
| 200 | 221 | const manageButton = await renderExtensionTemplateAsync('attachments', 'manage-button', {}); |
| 201 | 222 | const attachButton = await renderExtensionTemplateAsync('attachments', 'attach-button', {}); |
| 202 | 223 | $('#data_bank_wand_container').append(manageButton); |
| @@ -466,13 +466,13 @@ async function ingestDataBankAttachments(source) { | ||
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // Download and process the file |
| 469 | 469 | file.textconst fileText = await getFileAttachment(file.url); |
| 470 | 470 | console.log(`Vectors: Retrieved file ${file.name} from Data Bank`); |
| 471 | 471 | // Convert kilobytes to string length |
| 472 | 472 | const thresholdLength = settings.size_threshold_db * 1024; |
| 473 | 473 | // Use chunk size from settings if file is larger than threshold |
| 474 | 474 | const chunkSize = file.size > thresholdLength ? settings.chunk_size_db : -1; |
| 475 | 475 | await vectorizeFile(file.textfileText, file.name, collectionId, chunkSize, settings.overlap_percent_db); |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | return dataBankCollectionIds; |