mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Insert files before user text, not after
This commit is contained in:
@@ -3027,8 +3027,9 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
const fileText = chatItem.extra.file.text || (await getFileAttachment(chatItem.extra.file.url));
|
const fileText = chatItem.extra.file.text || (await getFileAttachment(chatItem.extra.file.url));
|
||||||
|
|
||||||
if (fileText) {
|
if (fileText) {
|
||||||
chatItem.extra.fileStart = regexedMessage.length;
|
const fileWrapped = `\`\`\`\n${fileText}\n\`\`\`\n\n`;
|
||||||
regexedMessage += `\n\n${fileText}`;
|
chatItem.extra.fileLength = fileWrapped.length;
|
||||||
|
regexedMessage = fileWrapped + regexedMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,9 +23,9 @@ const settings = {
|
|||||||
|
|
||||||
// For files
|
// For files
|
||||||
enabled_files: false,
|
enabled_files: false,
|
||||||
size_threshold: 5,
|
size_threshold: 10,
|
||||||
chunk_size: 1000,
|
chunk_size: 5000,
|
||||||
chunk_count: 4,
|
chunk_count: 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
const moduleWorker = new ModuleWorkerWrapper(synchronizeChat);
|
const moduleWorker = new ModuleWorkerWrapper(synchronizeChat);
|
||||||
@@ -176,7 +176,9 @@ async function processFiles(chat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Trim file inserted by the script
|
// Trim file inserted by the script
|
||||||
const fileText = message.mes.substring(message.extra.fileStart).trim();
|
const fileText = String(message.mes)
|
||||||
|
.substring(0, message.extra.fileLength).trim()
|
||||||
|
.replace(/^```/, '').replace(/```$/, '').trim();
|
||||||
|
|
||||||
// Convert kilobytes to string length
|
// Convert kilobytes to string length
|
||||||
const thresholdLength = settings.size_threshold * 1024;
|
const thresholdLength = settings.size_threshold * 1024;
|
||||||
@@ -186,7 +188,7 @@ async function processFiles(chat) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.mes = message.mes.substring(0, message.extra.fileStart);
|
message.mes = message.mes.substring(message.extra.fileLength);
|
||||||
|
|
||||||
const fileName = message.extra.file.name;
|
const fileName = message.extra.file.name;
|
||||||
const collectionId = `file_${getStringHash(fileName)}`;
|
const collectionId = `file_${getStringHash(fileName)}`;
|
||||||
@@ -200,7 +202,8 @@ async function processFiles(chat) {
|
|||||||
const queryText = getQueryText(chat);
|
const queryText = getQueryText(chat);
|
||||||
const fileChunks = await retrieveFileChunks(queryText, collectionId);
|
const fileChunks = await retrieveFileChunks(queryText, collectionId);
|
||||||
|
|
||||||
message.mes += '\n\n' + fileChunks;
|
// Wrap it back in a code block
|
||||||
|
message.mes = `\`\`\`\n${fileChunks}\n\`\`\`\n\n${message.mes}`;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Vectors: Failed to retrieve files', error);
|
console.error('Vectors: Failed to retrieve files', error);
|
||||||
|
Reference in New Issue
Block a user