mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add experimental setting for file translation
This commit is contained in:
@ -53,6 +53,7 @@ const settings = {
|
|||||||
|
|
||||||
// For files
|
// For files
|
||||||
enabled_files: false,
|
enabled_files: false,
|
||||||
|
translate_files: false,
|
||||||
size_threshold: 10,
|
size_threshold: 10,
|
||||||
chunk_size: 5000,
|
chunk_size: 5000,
|
||||||
chunk_count: 2,
|
chunk_count: 2,
|
||||||
@ -437,6 +438,12 @@ async function retrieveFileChunks(queryText, collectionId) {
|
|||||||
*/
|
*/
|
||||||
async function vectorizeFile(fileText, fileName, collectionId, chunkSize) {
|
async function vectorizeFile(fileText, fileName, collectionId, chunkSize) {
|
||||||
try {
|
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 toast = toastr.info('Vectorization may take some time, please wait...', `Ingesting file ${fileName}`);
|
||||||
const chunks = splitRecursive(fileText, chunkSize);
|
const chunks = splitRecursive(fileText, chunkSize);
|
||||||
console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks`, chunks);
|
console.debug(`Vectors: Split file ${fileName} into ${chunks.length} chunks`, chunks);
|
||||||
@ -1121,6 +1128,12 @@ jQuery(async () => {
|
|||||||
saveSettingsDebounced();
|
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 validSecret = !!secret_state[SECRET_KEYS.NOMICAI];
|
||||||
const placeholder = validSecret ? '✔️ Key saved' : '❌ Missing key';
|
const placeholder = validSecret ? '✔️ Key saved' : '❌ Missing key';
|
||||||
$('#api_key_nomicai').attr('placeholder', placeholder);
|
$('#api_key_nomicai').attr('placeholder', placeholder);
|
||||||
|
@ -107,6 +107,13 @@
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div id="vectors_files_settings" class="marginTopBot5">
|
<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.">
|
<div class="flex justifyCenter" title="These settings apply to files attached directly to messages.">
|
||||||
<span>Message attachments</span>
|
<span>Message attachments</span>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user