Case-Sensitive
@@ -4395,7 +4395,7 @@
Match Whole Words
From c76cc20a7d770a0bd303f459541aa4dd51228978 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Wed, 24 Jan 2024 13:00:43 +0200
Subject: [PATCH 06/10] Fix default value for new fields
---
public/scripts/world-info.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js
index 6e28b08ae..a6a551792 100644
--- a/public/scripts/world-info.js
+++ b/public/scripts/world-info.js
@@ -1540,7 +1540,7 @@ function getWorldEntry(name, data, entry) {
setOriginalDataValue(data, uid, 'extensions.case_sensitive', data.entries[uid].caseSensitive);
saveWorldInfo(name, data);
});
- caseSensitiveSelect.val(entry.caseSensitive === null ? 'null' : entry.caseSensitive ? 'true' : 'false').trigger('input');
+ caseSensitiveSelect.val((entry.caseSensitive === null || entry.caseSensitive === undefined) ? 'null' : entry.caseSensitive ? 'true' : 'false').trigger('input');
// match whole words select
const matchWholeWordsSelect = template.find('select[name="matchWholeWords"]');
@@ -1553,7 +1553,7 @@ function getWorldEntry(name, data, entry) {
setOriginalDataValue(data, uid, 'extensions.match_whole_words', data.entries[uid].matchWholeWords);
saveWorldInfo(name, data);
});
- matchWholeWordsSelect.val(entry.matchWholeWords === null ? 'null' : entry.matchWholeWords ? 'true' : 'false').trigger('input');
+ matchWholeWordsSelect.val((entry.matchWholeWords === null || entry.matchWholeWords === undefined) ? 'null' : entry.matchWholeWords ? 'true' : 'false').trigger('input');
template.find('.inline-drawer-content').css('display', 'none'); //entries start collapsed
From e329bd8497ba68d9af180812d3dfb0919e888c98 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Wed, 24 Jan 2024 13:07:56 +0200
Subject: [PATCH 07/10] Fix JSdoc comments
---
public/scripts/world-info.js | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js
index a6a551792..5b3edd40e 100644
--- a/public/scripts/world-info.js
+++ b/public/scripts/world-info.js
@@ -81,7 +81,7 @@ class WorldInfoBuffer {
// End typedef area
/**
- * @type {string[]} Key is the depth, value is an array of messages
+ * @type {string[]} Array of messages sorted by ascending depth
*/
#depthBuffer = [];
@@ -91,7 +91,7 @@ class WorldInfoBuffer {
#recurseBuffer = [];
/**
- * @type {number} The skew of the buffer. Used in "min activations"
+ * @type {number} The skew of the global scan depth. Used in "min activations"
*/
#skew = 0;
@@ -154,7 +154,6 @@ class WorldInfoBuffer {
return this.#transformString(result, entry);
}
-
/**
* Matches the given string against the buffer.
* @param {string} haystack The string to search in
@@ -178,7 +177,6 @@ class WorldInfoBuffer {
return true;
}
}
-
} else {
return haystack.includes(transformedString);
}
From cfdf43a26e2e709e5c863d00c378caf216516ab7 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Wed, 24 Jan 2024 13:56:13 +0200
Subject: [PATCH 08/10] #1671 Add batch vectorization
---
src/embedding.js | 15 +++++++++++++++
src/endpoints/vectors.js | 32 ++++++++++++++++++++++++++------
src/makersuite-vectors.js | 12 ++++++++++++
src/openai-vectors.js | 33 ++++++++++++++++++++++++---------
4 files changed, 77 insertions(+), 15 deletions(-)
diff --git a/src/embedding.js b/src/embedding.js
index bf42080aa..eabc0cc43 100644
--- a/src/embedding.js
+++ b/src/embedding.js
@@ -1,6 +1,7 @@
const TASK = 'feature-extraction';
/**
+ * Gets the vectorized text in form of an array of numbers.
* @param {string} text - The text to vectorize
* @returns {Promise} - The vectorized text in form of an array of numbers
*/
@@ -12,6 +13,20 @@ async function getTransformersVector(text) {
return vector;
}
+/**
+ * Gets the vectorized texts in form of an array of arrays of numbers.
+ * @param {string[]} texts - The texts to vectorize
+ * @returns {Promise} - The vectorized texts in form of an array of arrays of numbers
+ */
+async function getTransformersBatchVector(texts) {
+ const result = [];
+ for (const text of texts) {
+ result.push(await getTransformersVector(text));
+ }
+ return result;
+}
+
module.exports = {
getTransformersVector,
+ getTransformersBatchVector,
};
diff --git a/src/endpoints/vectors.js b/src/endpoints/vectors.js
index 45d4d55a6..cc2cfedf9 100644
--- a/src/endpoints/vectors.js
+++ b/src/endpoints/vectors.js
@@ -24,6 +24,26 @@ async function getVector(source, text) {
throw new Error(`Unknown vector source ${source}`);
}
+/**
+ * Gets the vector for the given text batch from the given source.
+ * @param {string} source - The source of the vector
+ * @param {string[]} texts - The array of texts to get the vector for
+ * @returns {Promise} - The array of vectors for the texts
+ */
+async function getBatchVector(source, texts) {
+ switch (source) {
+ case 'mistral':
+ case 'openai':
+ return require('../openai-vectors').getOpenAIBatchVector(texts, source);
+ case 'transformers':
+ return require('../embedding').getTransformersBatchVector(texts);
+ case 'palm':
+ return require('../makersuite-vectors').getMakerSuiteBatchVector(texts);
+ }
+
+ throw new Error(`Unknown vector source ${source}`);
+}
+
/**
* Gets the index for the vector collection
* @param {string} collectionId - The collection ID
@@ -52,12 +72,12 @@ async function insertVectorItems(collectionId, source, items) {
await store.beginUpdate();
- for (const item of items) {
- const text = item.text;
- const hash = item.hash;
- const index = item.index;
- const vector = await getVector(source, text);
- await store.upsertItem({ vector: vector, metadata: { hash, text, index } });
+ const vectors = await getBatchVector(source, items.map(x => x.text));
+
+ for (let i = 0; i < items.length; i++) {
+ const item = items[i];
+ const vector = vectors[i];
+ await store.upsertItem({ vector: vector, metadata: { hash: item.hash, text: item.text, index: item.index } });
}
await store.endUpdate();
diff --git a/src/makersuite-vectors.js b/src/makersuite-vectors.js
index 66d1a6fd8..efb3dd7ad 100644
--- a/src/makersuite-vectors.js
+++ b/src/makersuite-vectors.js
@@ -1,6 +1,17 @@
const fetch = require('node-fetch').default;
const { SECRET_KEYS, readSecret } = require('./endpoints/secrets');
+/**
+ * Gets the vector for the given text from gecko model
+ * @param {string[]} texts - The array of texts to get the vector for
+ * @returns {Promise} - The array of vectors for the texts
+ */
+async function getMakerSuiteBatchVector(texts) {
+ const promises = texts.map(text => getMakerSuiteVector(text));
+ const vectors = await Promise.all(promises);
+ return vectors;
+}
+
/**
* Gets the vector for the given text from PaLM gecko model
* @param {string} text - The text to get the vector for
@@ -40,4 +51,5 @@ async function getMakerSuiteVector(text) {
module.exports = {
getMakerSuiteVector,
+ getMakerSuiteBatchVector,
};
diff --git a/src/openai-vectors.js b/src/openai-vectors.js
index 3b19a4c96..2a0281e9c 100644
--- a/src/openai-vectors.js
+++ b/src/openai-vectors.js
@@ -3,7 +3,7 @@ const { SECRET_KEYS, readSecret } = require('./endpoints/secrets');
const SOURCES = {
'mistral': {
- secretKey: SECRET_KEYS.MISTRAL,
+ secretKey: SECRET_KEYS.MISTRALAI,
url: 'api.mistral.ai',
model: 'mistral-embed',
},
@@ -15,12 +15,12 @@ const SOURCES = {
};
/**
- * Gets the vector for the given text from an OpenAI compatible endpoint.
- * @param {string} text - The text to get the vector for
+ * Gets the vector for the given text batch from an OpenAI compatible endpoint.
+ * @param {string[]} texts - The array of texts to get the vector for
* @param {string} source - The source of the vector
- * @returns {Promise} - The vector for the text
+ * @returns {Promise} - The array of vectors for the texts
*/
-async function getOpenAIVector(text, source) {
+async function getOpenAIBatchVector(texts, source) {
const config = SOURCES[source];
if (!config) {
@@ -43,7 +43,7 @@ async function getOpenAIVector(text, source) {
Authorization: `Bearer ${key}`,
},
body: JSON.stringify({
- input: text,
+ input: texts,
model: config.model,
}),
});
@@ -55,16 +55,31 @@ async function getOpenAIVector(text, source) {
}
const data = await response.json();
- const vector = data?.data[0]?.embedding;
- if (!Array.isArray(vector)) {
+ if (!Array.isArray(data?.data)) {
console.log('API response was not an array');
throw new Error('API response was not an array');
}
- return vector;
+ // Sort data by x.index to ensure the order is correct
+ data.data.sort((a, b) => a.index - b.index);
+
+ const vectors = data.data.map(x => x.embedding);
+ return vectors;
+}
+
+/**
+ * Gets the vector for the given text from an OpenAI compatible endpoint.
+ * @param {string} text - The text to get the vector for
+ * @param {string} source - The source of the vector
+ * @returns {Promise} - The vector for the text
+ */
+async function getOpenAIVector(text, source) {
+ const vectors = await getOpenAIBatchVector([text], source);
+ return vectors[0];
}
module.exports = {
getOpenAIVector,
+ getOpenAIBatchVector,
};
From d5a2f5d9fc0bb27d7441c879446c3e51be916067 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Wed, 24 Jan 2024 14:04:45 +0200
Subject: [PATCH 09/10] Fix /rand returning zero #1728
---
public/scripts/variables.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/scripts/variables.js b/public/scripts/variables.js
index ff9d6bd42..a3a8b6f9d 100644
--- a/public/scripts/variables.js
+++ b/public/scripts/variables.js
@@ -664,7 +664,7 @@ function randValuesCallback(from, to, args) {
if (args.round == 'floor') {
return Math.floor(value);
}
- return value;
+ return String(value);
}
export function registerVariableCommands() {
From 625a07ac1f02c896191030feeb2ef6ee4edbae4d Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Wed, 24 Jan 2024 14:25:13 +0200
Subject: [PATCH 10/10] Fix Chrome 121 scrollbars
---
public/style.css | 3 ---
1 file changed, 3 deletions(-)
diff --git a/public/style.css b/public/style.css
index 864ac23f5..3e06fdbca 100644
--- a/public/style.css
+++ b/public/style.css
@@ -538,7 +538,6 @@ hr {
background-color: var(--SmartThemeChatTintColor);
-webkit-backdrop-filter: blur(var(--SmartThemeBlurStrength));
text-shadow: 0px 0px calc(var(--shadowWidth) * 1px) var(--SmartThemeShadowColor);
- scrollbar-width: thin;
flex-direction: column;
z-index: 30;
}
@@ -979,7 +978,6 @@ textarea {
font-size: var(--mainFontSize);
font-family: "Noto Sans", "Noto Color Emoji", sans-serif;
padding: 5px 10px;
- scrollbar-width: thin;
max-height: 90vh;
max-height: 90svh;
}
@@ -3125,7 +3123,6 @@ a {
box-shadow: none;
border-radius: 10px;
overflow: hidden;
- scrollbar-width: thin;
flex-flow: column;
min-width: 100px;
}