mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-05 13:36:47 +01:00
Adjust chromadb auto% for character description
This commit is contained in:
parent
a0c8ac54dd
commit
bad7892baa
@ -544,6 +544,30 @@ async function onSelectInjectFile(e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the length of character description in the current context
|
||||
function getCharacterDataLength() {
|
||||
const context = getContext();
|
||||
const character = context.characters[context.characterId];
|
||||
|
||||
if (typeof character?.data !== 'object') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let characterDataLength = 0;
|
||||
|
||||
for (const [key, value] of Object.entries(character.data)) {
|
||||
if (typeof value !== 'string') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (['description', 'personality', 'scenario'].includes(key)) {
|
||||
characterDataLength += character.data[key].length;
|
||||
}
|
||||
}
|
||||
|
||||
return characterDataLength;
|
||||
}
|
||||
|
||||
/*
|
||||
* Automatically adjusts the extension settings for the optimal number of messages to keep and query based
|
||||
* on the chat history and a specified maximum context length.
|
||||
@ -558,6 +582,10 @@ function doAutoAdjust(chat, maxContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Adjust max context for character defs length
|
||||
maxContext = Math.floor(maxContext - (getCharacterDataLength() / CHARACTERS_PER_TOKEN_RATIO));
|
||||
console.debug('CHROMADB: Max context adjusted for character defs: %o', maxContext);
|
||||
|
||||
console.debug('CHROMADB: Mean message length (characters): %o', meanMessageLength);
|
||||
// Convert to number of "tokens"
|
||||
const meanMessageLengthTokens = Math.ceil(meanMessageLength / CHARACTERS_PER_TOKEN_RATIO);
|
||||
|
Loading…
Reference in New Issue
Block a user