chore: Add index property to HashedMessage

02900520c9e5cc2eb8312827b6a26f1b95a59c8d

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +2 -1Ignore whitespace
public/scripts/extensions/vectors/index.js+2 -1
@@ -37,6 +37,7 @@ import { generateWebLlmChatPrompt, isWebLlmSupported } from '../shared.js';
37 * @typedef {object} HashedMessage37 * @typedef {object} HashedMessage
38 * @property {string} text - The hashed message text38 * @property {string} text - The hashed message text
39 * @property {number} hash - The hash used as the vector key39 * @property {number} hash - The hash used as the vector key
40 * @property {number} index - The index of the message in the chat
40 */41 */
4142
42const MODULE_NAME = 'vectors';43const MODULE_NAME = 'vectors';
@@ -725,7 +726,7 @@ const onChatEvent = debounce(async () => await moduleWorker.update(), debounce_t
725 */726 */
726async function getQueryText(chat, initiator) {727async function getQueryText(chat, initiator) {
727 let hashedMessages = chat728 let hashedMessages = chat
728 .map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)) }))729 .map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)), index: chat.indexOf(x) }))
729 .filter(x => x.text)730 .filter(x => x.text)
730 .reverse()731 .reverse()
731 .slice(0, settings.query);732 .slice(0, settings.query);