mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Replace object stores for Chroma and token cache
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
import { saveSettingsDebounced, getCurrentChatId, system_message_types, extension_prompt_types, eventSource, event_types, getRequestHeaders, CHARACTERS_PER_TOKEN_RATIO, substituteParams, max_context, } from "../../../script.js";
|
||||
import { humanizedDateTime } from "../../RossAscends-mods.js";
|
||||
import { getApiUrl, extension_settings, getContext, doExtrasFetch } from "../../extensions.js";
|
||||
import { getFileText, onlyUnique, splitRecursive, IndexedDBStore } from "../../utils.js";
|
||||
import { getFileText, onlyUnique, splitRecursive } from "../../utils.js";
|
||||
export { MODULE_NAME };
|
||||
|
||||
const MODULE_NAME = 'chromadb';
|
||||
const dbStore = new IndexedDBStore('SillyTavern', MODULE_NAME);
|
||||
const dbStore = localforage.createInstance({ name: 'SillyTavern_ChromaDB' });
|
||||
|
||||
const defaultSettings = {
|
||||
strategy: 'original',
|
||||
@ -59,7 +59,7 @@ async function invalidateMessageSyncState(messageId) {
|
||||
console.log('CHROMADB: invalidating message sync state', messageId);
|
||||
const state = await getChatSyncState();
|
||||
state[messageId] = 0;
|
||||
await dbStore.put(getCurrentChatId(), state);
|
||||
await dbStore.setItem(getCurrentChatId(), state);
|
||||
}
|
||||
|
||||
async function getChatSyncState() {
|
||||
@ -69,7 +69,7 @@ async function getChatSyncState() {
|
||||
}
|
||||
|
||||
const context = getContext();
|
||||
const chatState = (await dbStore.get(currentChatId)) || [];
|
||||
const chatState = (await dbStore.getItem(currentChatId)) || [];
|
||||
|
||||
// if the chat length has decreased, it means that some messages were deleted
|
||||
if (chatState.length > context.chat.length) {
|
||||
@ -92,7 +92,7 @@ async function getChatSyncState() {
|
||||
chatState[i] = 0;
|
||||
}
|
||||
}
|
||||
await dbStore.put(currentChatId, chatState);
|
||||
await dbStore.setItem(currentChatId, chatState);
|
||||
|
||||
return chatState;
|
||||
}
|
||||
@ -304,7 +304,7 @@ async function filterSyncedMessages(splitMessages) {
|
||||
}
|
||||
|
||||
console.debug('CHROMADB: sync state', syncState.map((v, i) => ({ id: i, synced: v })));
|
||||
await dbStore.put(getCurrentChatId(), syncState);
|
||||
await dbStore.setItem(getCurrentChatId(), syncState);
|
||||
|
||||
// remove messages that are already synced
|
||||
return splitMessages.filter((_, i) => !removeIndices.includes(i));
|
||||
@ -325,7 +325,7 @@ async function onPurgeClick() {
|
||||
});
|
||||
|
||||
if (purgeResult.ok) {
|
||||
await dbStore.delete(chat_id);
|
||||
await dbStore.removeItem(chat_id);
|
||||
toastr.success('ChromaDB context has been successfully cleared');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user