#2164 Add error toasts to VecStore

This commit is contained in:
Cohee 2024-04-30 00:17:39 +03:00
parent 993284f9c1
commit d9d76ba16d
1 changed files with 18 additions and 3 deletions

View File

@ -281,7 +281,7 @@ async function synchronizeChat(batchSize = 5) {
console.error('Vectors: Failed to synchronize chat', error);
const message = getErrorMessage(error.cause);
toastr.error(message, 'Vectorization failed');
toastr.error(message, 'Vectorization failed', { preventDuplicates: true });
return -1;
} finally {
syncBlocked = false;
@ -444,6 +444,7 @@ async function retrieveFileChunks(queryText, collectionId) {
* @param {string} fileName File name
* @param {string} collectionId File collection ID
* @param {number} chunkSize Chunk size
* @returns {Promise<boolean>} True if successful, false if not
*/
async function vectorizeFile(fileText, fileName, collectionId, chunkSize) {
try {
@ -462,8 +463,11 @@ async function vectorizeFile(fileText, fileName, collectionId, chunkSize) {
toastr.clear(toast);
console.log(`Vectors: Inserted ${chunks.length} vector items for file ${fileName} into ${collectionId}`);
return true;
} catch (error) {
toastr.error(String(error), 'Failed to vectorize file', { preventDuplicates: true });
console.error('Vectors: Failed to vectorize file', error);
return false;
}
}
@ -546,6 +550,7 @@ async function rearrangeChat(chat) {
const insertedText = getPromptText(queriedMessages);
setExtensionPrompt(EXTENSION_PROMPT_TAG, insertedText, settings.position, settings.depth, settings.include_wi);
} catch (error) {
toastr.error('Generation interceptor aborted. Check browser console for more details.', 'Vector Storage');
console.error('Vectors: Failed to rearrange chat', error);
}
}
@ -911,6 +916,8 @@ async function onVectorizeAllFilesClick() {
const chatAttachments = getContext().chat.filter(x => x.extra?.file).map(x => x.extra.file);
const allFiles = [...dataBank, ...chatAttachments];
let allSuccess = true;
for (const file of allFiles) {
const text = await getFileAttachment(file.url);
const collectionId = getFileCollectionId(file.url);
@ -921,10 +928,18 @@ async function onVectorizeAllFilesClick() {
continue;
}
await vectorizeFile(text, file.name, collectionId, settings.chunk_size);
const result = await vectorizeFile(text, file.name, collectionId, settings.chunk_size);
if (!result) {
allSuccess = false;
}
}
toastr.success('All files vectorized', 'Vectorization successful');
if (allSuccess) {
toastr.success('All files vectorized', 'Vectorization successful');
} else {
toastr.warning('Some files failed to vectorize. Check browser console for more details.', 'Vector Storage');
}
} catch (error) {
console.error('Vectors: Failed to vectorize all files', error);
toastr.error('Failed to vectorize all files', 'Vectorization failed');