Fix character attachment content saving into settings.json
This commit is contained in:
parent
c59afd1b56
commit
1278b5c309
|
@ -1,3 +1,4 @@
|
|||
import { event_types, eventSource, saveSettingsDebounced } from '../../../script.js';
|
||||
import { deleteAttachment, getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment, uploadFileAttachmentToServer } from '../../chats.js';
|
||||
import { extension_settings, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||
import { SlashCommand } from '../../slash-commands/SlashCommand.js';
|
||||
|
@ -196,7 +197,27 @@ async function enableDataBankAttachment(args, value) {
|
|||
return '';
|
||||
}
|
||||
|
||||
function cleanUpAttachments() {
|
||||
let shouldSaveSettings = false;
|
||||
if (extension_settings.character_attachments) {
|
||||
Object.values(extension_settings.character_attachments).flat().filter(a => a.text).forEach(a => {
|
||||
shouldSaveSettings = true;
|
||||
delete a.text;
|
||||
});
|
||||
}
|
||||
if (Array.isArray(extension_settings.attachments)) {
|
||||
extension_settings.attachments.filter(a => a.text).forEach(a => {
|
||||
shouldSaveSettings = true;
|
||||
delete a.text;
|
||||
});
|
||||
}
|
||||
if (shouldSaveSettings) {
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
eventSource.on(event_types.APP_READY, cleanUpAttachments);
|
||||
const manageButton = await renderExtensionTemplateAsync('attachments', 'manage-button', {});
|
||||
const attachButton = await renderExtensionTemplateAsync('attachments', 'attach-button', {});
|
||||
$('#data_bank_wand_container').append(manageButton);
|
||||
|
|
|
@ -466,13 +466,13 @@ async function ingestDataBankAttachments(source) {
|
|||
}
|
||||
|
||||
// Download and process the file
|
||||
file.text = await getFileAttachment(file.url);
|
||||
const fileText = await getFileAttachment(file.url);
|
||||
console.log(`Vectors: Retrieved file ${file.name} from Data Bank`);
|
||||
// Convert kilobytes to string length
|
||||
const thresholdLength = settings.size_threshold_db * 1024;
|
||||
// Use chunk size from settings if file is larger than threshold
|
||||
const chunkSize = file.size > thresholdLength ? settings.chunk_size_db : -1;
|
||||
await vectorizeFile(file.text, file.name, collectionId, chunkSize, settings.overlap_percent_db);
|
||||
await vectorizeFile(fileText, file.name, collectionId, chunkSize, settings.overlap_percent_db);
|
||||
}
|
||||
|
||||
return dataBankCollectionIds;
|
||||
|
|
Loading…
Reference in New Issue