chore: Add index property to HashedMessage
| @@ -37,6 +37,7 @@ import { generateWebLlmChatPrompt, isWebLlmSupported } from '../shared.js'; | |||
| 37 | * @typedef {object} HashedMessage | 37 | * @typedef {object} HashedMessage |
| 38 | * @property {string} text - The hashed message text | 38 | * @property {string} text - The hashed message text |
| 39 | * @property {number} hash - The hash used as the vector key | 39 | * @property {number} hash - The hash used as the vector key |
| 40 | * @property {number} index - The index of the message in the chat | ||
| 40 | */ | 41 | */ |
| 41 | 42 | ||
| 42 | const MODULE_NAME = 'vectors'; | 43 | const MODULE_NAME = 'vectors'; |
| @@ -725,7 +726,7 @@ const onChatEvent = debounce(async () => await moduleWorker.update(), debounce_t | |||
| 725 | */ | 726 | */ |
| 726 | async function getQueryText(chat, initiator) { | 727 | async function getQueryText(chat, initiator) { |
| 727 | let hashedMessages = chat | 728 | 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); |