Fix character attachment content saving into settings.json
| @@ -1,3 +1,4 @@ | |||
| 1 | import { event_types, eventSource, saveSettingsDebounced } from '../../../script.js'; | ||
| 1 | import { deleteAttachment, getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment, uploadFileAttachmentToServer } from '../../chats.js'; | 2 | import { deleteAttachment, getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment, uploadFileAttachmentToServer } from '../../chats.js'; |
| 2 | import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js'; | 3 | import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 3 | import { SlashCommand } from '../../slash-commands/SlashCommand.js'; | 4 | import { SlashCommand } from '../../slash-commands/SlashCommand.js'; |
| @@ -196,7 +197,27 @@ async function enableDataBankAttachment(args, value) { | |||
| 196 | return ''; | 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 | jQuery(async () => { | 219 | jQuery(async () => { |
| 220 | eventSource.on(event_types.APP_READY, cleanUpAttachments); | ||
| 200 | const manageButton = await renderExtensionTemplateAsync('attachments', 'manage-button', {}); | 221 | const manageButton = await renderExtensionTemplateAsync('attachments', 'manage-button', {}); |
| 201 | const attachButton = await renderExtensionTemplateAsync('attachments', 'attach-button', {}); | 222 | const attachButton = await renderExtensionTemplateAsync('attachments', 'attach-button', {}); |
| 202 | $('#data_bank_wand_container').append(manageButton); | 223 | $('#data_bank_wand_container').append(manageButton); |
| @@ -466,13 +466,13 @@ async function ingestDataBankAttachments(source) { | |||
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | // Download and process the file | 468 | // Download and process the file |
| 469 | file.text = await getFileAttachment(file.url); | 469 | const fileText = await getFileAttachment(file.url); |
| 470 | console.log(`Vectors: Retrieved file ${file.name} from Data Bank`); | 470 | console.log(`Vectors: Retrieved file ${file.name} from Data Bank`); |
| 471 | // Convert kilobytes to string length | 471 | // Convert kilobytes to string length |
| 472 | const thresholdLength = settings.size_threshold_db * 1024; | 472 | const thresholdLength = settings.size_threshold_db * 1024; |
| 473 | // Use chunk size from settings if file is larger than threshold | 473 | // Use chunk size from settings if file is larger than threshold |
| 474 | const chunkSize = file.size > thresholdLength ? settings.chunk_size_db : -1; | 474 | const chunkSize = file.size > thresholdLength ? settings.chunk_size_db : -1; |
| 475 | await vectorizeFile(file.text, file.name, collectionId, chunkSize, settings.overlap_percent_db); | 475 | await vectorizeFile(fileText, file.name, collectionId, chunkSize, settings.overlap_percent_db); |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | return dataBankCollectionIds; | 478 | return dataBankCollectionIds; |