+ The model must be downloaded first! Do it with the ollama pull command or click here.
+
-
- Hint: Download models and set the URL in the API connection settings.
+
+ The model must be downloaded first! Do it with the ollama pull command or click here.
+
+
+ Hint: Set the URL in the API connection settings.
From 8564d6faa8050e8454c8d8a1e909531456bfc393 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sat, 22 Jun 2024 17:41:02 +0300
Subject: [PATCH 3/7] Debug function to purge all vectors
---
public/scripts/extensions/vectors/index.js | 31 +++++++++++++++++++++-
src/endpoints/vectors.js | 19 +++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/public/scripts/extensions/vectors/index.js b/public/scripts/extensions/vectors/index.js
index 54c178b53..fc5fd8813 100644
--- a/public/scripts/extensions/vectors/index.js
+++ b/public/scripts/extensions/vectors/index.js
@@ -20,7 +20,7 @@ import {
renderExtensionTemplateAsync,
doExtrasFetch, getApiUrl,
} from '../../extensions.js';
-import { collapseNewlines } from '../../power-user.js';
+import { collapseNewlines, registerDebugFunction } from '../../power-user.js';
import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js';
import { getDataBankAttachments, getDataBankAttachmentsForSource, getFileAttachment } from '../../chats.js';
import { debounce, getStringHash as calculateHash, waitUntilCondition, onlyUnique, splitRecursive, trimToStartSentence, trimToEndSentence } from '../../utils.js';
@@ -989,6 +989,28 @@ async function purgeVectorIndex(collectionId) {
}
}
+/**
+ * Purges all vector indexes.
+ */
+async function purgeAllVectorIndexes() {
+ try {
+ const response = await fetch('/api/vector/purge-all', {
+ method: 'POST',
+ headers: getRequestHeaders(),
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to purge all vector indexes');
+ }
+
+ console.log('Vectors: Purged all vector indexes');
+ toastr.success('All vector indexes purged', 'Purge successful');
+ } catch (error) {
+ console.error('Vectors: Failed to purge all', error);
+ toastr.error('Failed to purge all vector indexes', 'Purge failed');
+ }
+}
+
function toggleSettings() {
$('#vectors_files_settings').toggle(!!settings.enabled_files);
$('#vectors_chats_settings').toggle(!!settings.enabled_chats);
@@ -1578,4 +1600,11 @@ jQuery(async () => {
],
returns: ARGUMENT_TYPE.LIST,
}));
+
+ registerDebugFunction('purge-everything', 'Purge all vector indices', 'Obliterate all stored vectors for all sources. No mercy.', async () => {
+ if (!confirm('Are you sure?')) {
+ return;
+ }
+ await purgeAllVectorIndexes();
+ });
});
diff --git a/src/endpoints/vectors.js b/src/endpoints/vectors.js
index 74666e584..38f74f7d8 100644
--- a/src/endpoints/vectors.js
+++ b/src/endpoints/vectors.js
@@ -1,5 +1,6 @@
const vectra = require('vectra');
const path = require('path');
+const fs = require('fs');
const express = require('express');
const sanitize = require('sanitize-filename');
const { jsonParser } = require('../express-common');
@@ -440,6 +441,24 @@ router.post('/delete', jsonParser, async (req, res) => {
}
});
+router.post('/purge-all', jsonParser, async (req, res) => {
+ try {
+ for (const source of SOURCES) {
+ const sourcePath = path.join(req.user.directories.vectors, sanitize(source));
+ if (!fs.existsSync(sourcePath)) {
+ continue;
+ }
+ await fs.promises.rm(sourcePath, { recursive: true });
+ console.log(`Deleted vector source store at ${sourcePath}`);
+ }
+
+ return res.sendStatus(200);
+ } catch (error) {
+ console.error(error);
+ return res.sendStatus(500);
+ }
+});
+
router.post('/purge', jsonParser, async (req, res) => {
try {
if (!req.body.collectionId) {
From d64647280a20da9507209d912e67122ad256a877 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sat, 22 Jun 2024 17:41:40 +0300
Subject: [PATCH 4/7] Fix method deprecation warning
---
src/endpoints/extensions.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/endpoints/extensions.js b/src/endpoints/extensions.js
index d14ddb8cf..87c06da9c 100644
--- a/src/endpoints/extensions.js
+++ b/src/endpoints/extensions.js
@@ -191,7 +191,7 @@ router.post('/delete', jsonParser, async (request, response) => {
return response.status(400).send('Bad Request: extensionName is required in the request body.');
}
- // Sanatize the extension name to prevent directory traversal
+ // Sanitize the extension name to prevent directory traversal
const extensionName = sanitize(request.body.extensionName);
try {
@@ -201,7 +201,7 @@ router.post('/delete', jsonParser, async (request, response) => {
return response.status(404).send(`Directory does not exist at ${extensionPath}`);
}
- await fs.promises.rmdir(extensionPath, { recursive: true });
+ await fs.promises.rm(extensionPath, { recursive: true });
console.log(`Extension has been deleted at ${extensionPath}`);
return response.send(`Extension has been deleted at ${extensionPath}`);
From a39a1a7cec7020cac3114d9ad571c8e7b54ffce9 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sat, 22 Jun 2024 17:44:08 +0300
Subject: [PATCH 5/7] Fix odd-named preset selection via command
---
public/scripts/preset-manager.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/public/scripts/preset-manager.js b/public/scripts/preset-manager.js
index 42cc7585a..d751c5803 100644
--- a/public/scripts/preset-manager.js
+++ b/public/scripts/preset-manager.js
@@ -140,7 +140,10 @@ class PresetManager {
* @param {string} value Preset option value
*/
selectPreset(value) {
- $(this.select).find(`option[value=${value}]`).prop('selected', true);
+ const option = $(this.select).filter(function() {
+ return $(this).val() === value;
+ });
+ option.prop('selected', true);
$(this.select).val(value).trigger('change');
}
From de1910268a21da3acd50fed3658905cee2c90c54 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Sun, 23 Jun 2024 01:26:25 +0300
Subject: [PATCH 6/7] Add missing macro reference
---
public/scripts/templates/macros.html | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/public/scripts/templates/macros.html b/public/scripts/templates/macros.html
index 353dcc12e..8d2e4ebdd 100644
--- a/public/scripts/templates/macros.html
+++ b/public/scripts/templates/macros.html
@@ -21,9 +21,11 @@
{{char_version}} – the Character's version number
{{group}} – a comma-separated list of group member names or the character name in solo chats. Alias: {{charIfNotGroup}}
{{model}} – a text generation model name for the currently selected API. Can be inaccurate!
-
{{lastMessage}} - the text of the latest chat message.
+
{{lastMessage}} – the text of the latest chat message.
+
{{lastUserMessage}} – the text of the latest user chat message.
+
{{lastCharMessage}} – the text of the latest character chat message.
{{lastMessageId}} – index # of the latest chat message. Useful for slash command batching.
-
{{firstIncludedMessageId}} - the ID of the first message included in the context. Requires generation to be ran at least once in the current session.
+
{{firstIncludedMessageId}} – the ID of the first message included in the context. Requires generation to be ran at least once in the current session.
{{currentSwipeId}} – the 1-based ID of the current swipe in the last chat message. Empty string if the last message is user or prompt-hidden.
{{lastSwipeId}} – the number of swipes in the last chat message. Empty string if the last message is user or prompt-hidden.
{{// (note)}} – you can leave a note here, and the macro will be replaced with blank content. Not visible for the AI.