Add experimental setting for file translation
This commit is contained in:
parent
c2256c2ac7
commit
ca89be8930
|
@ -53,6 +53,7 @@ const settings = {
|
|||
|
||||
// For files
|
||||
enabled_files: false,
|
||||
translate_files: false,
|
||||
size_threshold: 10,
|
||||
chunk_size: 5000,
|
||||
chunk_count: 2,
|
||||
|
@ -437,6 +438,12 @@ async function retrieveFileChunks(queryText, collectionId) {
|
|||
*/
|
||||
async function vectorizeFile(fileText, fileName, collectionId, chunkSize) {
|
||||
try {
|
||||
if (settings.translate_files && typeof window['translate'] === 'function') {
|
||||
console.log(`Vectors: Translating file ${fileName} to English...`);
|
||||
const translatedText = await window['translate'](fileText, 'en');
|
||||
fileText = translatedText;
|
||||
}
|
||||
|
||||
const toast = toastr.info('Vectorization may take some time, please wait...', `Ingesting file ${fileName}`);
|
||||
const chunks = splitRecursive(fileText, chunkSize);
|
||||
console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks`, chunks);
|
||||
|
@ -1121,6 +1128,12 @@ jQuery(async () => {
|
|||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#vectors_translate_files').prop('checked', settings.translate_files).on('input', () => {
|
||||
settings.translate_files = !!$('#vectors_translate_files').prop('checked');
|
||||
Object.assign(extension_settings.vectors, settings);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
const validSecret = !!secret_state[SECRET_KEYS.NOMICAI];
|
||||
const placeholder = validSecret ? '✔️ Key saved' : '❌ Missing key';
|
||||
$('#api_key_nomicai').attr('placeholder', placeholder);
|
||||
|
|
|
@ -107,6 +107,13 @@
|
|||
</label>
|
||||
|
||||
<div id="vectors_files_settings" class="marginTopBot5">
|
||||
<label class="checkbox_label" for="vectors_translate_files" title="This can help with retrieval accuracy if using embedding models that are trained on English data. Uses the selected API from Chat Translation extension settings.">
|
||||
<input id="vectors_translate_files" type="checkbox" class="checkbox">
|
||||
<span data-i18n="Translate files into English before processing">
|
||||
Translate files into English before processing
|
||||
</span>
|
||||
<i class="fa-solid fa-flask" title="Experimental feature"></i>
|
||||
</label>
|
||||
<div class="flex justifyCenter" title="These settings apply to files attached directly to messages.">
|
||||
<span>Message attachments</span>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue