sillytavern 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +4 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/workflows/npm-publish.yml +32 -0
- package/Dockerfile +49 -0
- package/Start.bat +3 -0
- package/colab/GPU.ipynb +339 -0
- package/colab/extras_server.py +40 -0
- package/colab/globals.py +2 -0
- package/colab/models.py +77 -0
- package/docker/docker-compose.yml +12 -0
- package/docker/docker-entrypoint.sh +28 -0
- package/faq.md +208 -0
- package/package.json +49 -0
- package/poe-client.js +638 -0
- package/poe-test.js +21 -0
- package/poe_graphql/AddHumanMessageMutation.graphql +52 -0
- package/poe_graphql/AddMessageBreakMutation.graphql +17 -0
- package/poe_graphql/AutoSubscriptionMutation.graphql +7 -0
- package/poe_graphql/BioFragment.graphql +8 -0
- package/poe_graphql/ChatAddedSubscription.graphql +5 -0
- package/poe_graphql/ChatFragment.graphql +6 -0
- package/poe_graphql/ChatListPaginationQuery.graphql +316 -0
- package/poe_graphql/ChatPaginationQuery.graphql +26 -0
- package/poe_graphql/ChatViewQuery.graphql +8 -0
- package/poe_graphql/DeleteHumanMessagesMutation.graphql +7 -0
- package/poe_graphql/DeleteMessageMutation.graphql +7 -0
- package/poe_graphql/HandleFragment.graphql +8 -0
- package/poe_graphql/LoginWithVerificationCodeMutation.graphql +13 -0
- package/poe_graphql/MessageAddedSubscription.graphql +115 -0
- package/poe_graphql/MessageDeletedSubscription.graphql +8 -0
- package/poe_graphql/MessageFragment.graphql +13 -0
- package/poe_graphql/MessageRemoveVoteMutation.graphql +7 -0
- package/poe_graphql/MessageSetVoteMutation.graphql +7 -0
- package/poe_graphql/SendVerificationCodeForLoginMutation.graphql +12 -0
- package/poe_graphql/ShareMessagesMutation.graphql +9 -0
- package/poe_graphql/SignupWithVerificationCodeMutation.graphql +13 -0
- package/poe_graphql/StaleChatUpdateMutation.graphql +7 -0
- package/poe_graphql/SubscriptionsMutation.graphql +9 -0
- package/poe_graphql/SummarizePlainPostQuery.graphql +3 -0
- package/poe_graphql/SummarizeQuotePostQuery.graphql +3 -0
- package/poe_graphql/SummarizeSharePostQuery.graphql +3 -0
- package/poe_graphql/UserSnippetFragment.graphql +14 -0
- package/poe_graphql/ViewerInfoQuery.graphql +21 -0
- package/poe_graphql/ViewerMessageLimitUpdatedSubscription.graphql +81 -0
- package/poe_graphql/ViewerStateFragment.graphql +30 -0
- package/poe_graphql/ViewerStateUpdatedSubscription.graphql +63 -0
- package/public/KoboldAI Settings/Ace of Spades 13B.settings +22 -0
- package/public/KoboldAI Settings/Adventurer-NeoX-20B-Erebus.settings +54 -0
- package/public/KoboldAI Settings/Basic Coherence 13B.settings +22 -0
- package/public/KoboldAI Settings/Best Guess 6B.settings +22 -0
- package/public/KoboldAI Settings/Calibrated-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Classic-Pygmalion-2.7b.settings +46 -0
- package/public/KoboldAI Settings/Classic-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Coherent Creativity 6B.settings +22 -0
- package/public/KoboldAI Settings/Default-TavernAI.settings +22 -0
- package/public/KoboldAI Settings/DragonSlayer-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/GPU-Pygmalion-6b.settings +47 -0
- package/public/KoboldAI Settings/Genesis 13B.settings +22 -0
- package/public/KoboldAI Settings/Godlike.settings +22 -0
- package/public/KoboldAI Settings/Good Winds.settings +22 -0
- package/public/KoboldAI Settings/Lancer-OPT-2.7B-Erebus.settings +54 -0
- package/public/KoboldAI Settings/Liminal Drift.settings +22 -0
- package/public/KoboldAI Settings/Low Rider 13B.settings +22 -0
- package/public/KoboldAI Settings/Luna Moth 6B.settings +22 -0
- package/public/KoboldAI Settings/Mayday.settings +22 -0
- package/public/KoboldAI Settings/Ouroboros.settings +22 -0
- package/public/KoboldAI Settings/Pleasing Results 6B.settings +22 -0
- package/public/KoboldAI Settings/Pro Writer 13B.settings +22 -0
- package/public/KoboldAI Settings/RA - Pygmalion-1.3b.settings +46 -0
- package/public/KoboldAI Settings/Storywriter 6B.settings +22 -0
- package/public/NovelAI Settings/Classic-Euterpe.settings +14 -0
- package/public/NovelAI Settings/Classic-Krake.settings +14 -0
- package/public/OpenAI Settings/Default.settings +15 -0
- package/public/TextGen Settings/Beam Search.settings +15 -0
- package/public/TextGen Settings/Contrastive Search.settings +15 -0
- package/public/TextGen Settings/Default.settings +15 -0
- package/public/TextGen Settings/Deterministic.settings +15 -0
- package/public/TextGen Settings/Kobold (Godlike).settings +15 -0
- package/public/TextGen Settings/Kobold (Liminal Drift).settings +15 -0
- package/public/TextGen Settings/Naive.settings +15 -0
- package/public/TextGen Settings/NovelAI (Best Guess).settings +15 -0
- package/public/TextGen Settings/NovelAI (Decadence).settings +15 -0
- package/public/TextGen Settings/NovelAI (Genesis).settings +15 -0
- package/public/TextGen Settings/NovelAI (Lycaenidae).settings +15 -0
- package/public/TextGen Settings/NovelAI (Ouroboros).settings +15 -0
- package/public/TextGen Settings/NovelAI (Pleasing Results).settings +15 -0
- package/public/TextGen Settings/NovelAI (Sphinx Moth).settings +15 -0
- package/public/TextGen Settings/NovelAI (Storywriter).settings +15 -0
- package/public/TextGen Settings/Pygmalion.settings +15 -0
- package/public/css/fontawesome.css +8488 -0
- package/public/css/notes.css +46 -0
- package/public/css/solid.css +24 -0
- package/public/favicon.ico +0 -0
- package/public/img/No-Image-Placeholder.svg +309 -0
- package/public/img/addbg3.png +0 -0
- package/public/img/ai4.png +0 -0
- package/public/img/apple-icon-114x114.png +0 -0
- package/public/img/apple-icon-144x144.png +0 -0
- package/public/img/apple-icon-57x57.png +0 -0
- package/public/img/apple-icon-72x72.png +0 -0
- package/public/img/book2.png +0 -0
- package/public/img/default-expressions/admiration.png +0 -0
- package/public/img/default-expressions/amusement.png +0 -0
- package/public/img/default-expressions/anger.png +0 -0
- package/public/img/default-expressions/annoyance.png +0 -0
- package/public/img/default-expressions/approval.png +0 -0
- package/public/img/default-expressions/caring.png +0 -0
- package/public/img/default-expressions/confusion.png +0 -0
- package/public/img/default-expressions/curiosity.png +0 -0
- package/public/img/default-expressions/desire.png +0 -0
- package/public/img/default-expressions/desire1.png +0 -0
- package/public/img/default-expressions/desire2.png +0 -0
- package/public/img/default-expressions/disappointment.png +0 -0
- package/public/img/default-expressions/disapproval.png +0 -0
- package/public/img/default-expressions/disgust.png +0 -0
- package/public/img/default-expressions/embarrassment.png +0 -0
- package/public/img/default-expressions/excitement.png +0 -0
- package/public/img/default-expressions/fear.png +0 -0
- package/public/img/default-expressions/gratitude.png +0 -0
- package/public/img/default-expressions/grief.png +0 -0
- package/public/img/default-expressions/joy.png +0 -0
- package/public/img/default-expressions/love.png +0 -0
- package/public/img/default-expressions/nervousness.png +0 -0
- package/public/img/default-expressions/neutral.png +0 -0
- package/public/img/default-expressions/optimism.png +0 -0
- package/public/img/default-expressions/pride.png +0 -0
- package/public/img/default-expressions/realization.png +0 -0
- package/public/img/default-expressions/relief.png +0 -0
- package/public/img/default-expressions/remorse.png +0 -0
- package/public/img/default-expressions/sadness.png +0 -0
- package/public/img/default-expressions/surprise.png +0 -0
- package/public/img/five.png +0 -0
- package/public/img/times-circle.svg +1 -0
- package/public/img/you.png +0 -0
- package/public/index.html +1899 -0
- package/public/notes/1.html +44 -0
- package/public/notes/1.png +0 -0
- package/public/notes/10.html +20 -0
- package/public/notes/11.html +33 -0
- package/public/notes/12.html +27 -0
- package/public/notes/13.html +29 -0
- package/public/notes/13_1.html +24 -0
- package/public/notes/13_2.html +25 -0
- package/public/notes/13_3.html +89 -0
- package/public/notes/14.html +30 -0
- package/public/notes/2.html +37 -0
- package/public/notes/2.png +0 -0
- package/public/notes/3.html +37 -0
- package/public/notes/4.html +105 -0
- package/public/notes/6.html +33 -0
- package/public/notes/7.html +40 -0
- package/public/notes/8.html +19 -0
- package/public/notes/9.html +46 -0
- package/public/notes/advanced_formatting.html +91 -0
- package/public/notes/group_reply_strategy.html +63 -0
- package/public/notes/message_sound.html +33 -0
- package/public/notes/multigen.html +36 -0
- package/public/notes/oai_api_key.html +37 -0
- package/public/notes/textgen_streaming.html +29 -0
- package/public/notes/token-limits.html +68 -0
- package/public/script.js +5131 -0
- package/public/scripts/RossAscends-mods.js +750 -0
- package/public/scripts/bookmarks.js +130 -0
- package/public/scripts/extensions/backgrounds/index.js +129 -0
- package/public/scripts/extensions/backgrounds/manifest.json +11 -0
- package/public/scripts/extensions/backgrounds/style.css +45 -0
- package/public/scripts/extensions/caption/index.js +117 -0
- package/public/scripts/extensions/caption/manifest.json +13 -0
- package/public/scripts/extensions/caption/style.css +23 -0
- package/public/scripts/extensions/dice/droll.js +108 -0
- package/public/scripts/extensions/dice/index.js +96 -0
- package/public/scripts/extensions/dice/manifest.json +11 -0
- package/public/scripts/extensions/dice/style.css +26 -0
- package/public/scripts/extensions/expressions/index.js +387 -0
- package/public/scripts/extensions/expressions/manifest.json +13 -0
- package/public/scripts/extensions/expressions/style.css +115 -0
- package/public/scripts/extensions/floating-prompt/index.js +151 -0
- package/public/scripts/extensions/floating-prompt/manifest.json +11 -0
- package/public/scripts/extensions/floating-prompt/style.css +19 -0
- package/public/scripts/extensions/memory/index.js +358 -0
- package/public/scripts/extensions/memory/manifest.json +13 -0
- package/public/scripts/extensions/memory/style.css +34 -0
- package/public/scripts/extensions.js +288 -0
- package/public/scripts/f-localStorage.js +27 -0
- package/public/scripts/gpt-2-3-tokenizer/README.md +28 -0
- package/public/scripts/gpt-2-3-tokenizer/encoder.js +1 -0
- package/public/scripts/gpt-2-3-tokenizer/mod.js +169 -0
- package/public/scripts/gpt-2-3-tokenizer/vocab.bpe.js +1 -0
- package/public/scripts/gpt-3-tokenizer/array-keyed-map.js +210 -0
- package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js +271 -0
- package/public/scripts/gpt-3-tokenizer/gpt3-tokenizer.js.map +1 -0
- package/public/scripts/group-chats.js +899 -0
- package/public/scripts/horde.js +214 -0
- package/public/scripts/jquery-3.5.1.min.js +2 -0
- package/public/scripts/jquery-cookie-1.4.1.min.js +2 -0
- package/public/scripts/jquery.transit.min.js +1 -0
- package/public/scripts/kai-settings.js +179 -0
- package/public/scripts/nai-settings.js +108 -0
- package/public/scripts/openai.js +973 -0
- package/public/scripts/poe.js +360 -0
- package/public/scripts/popper.js +2008 -0
- package/public/scripts/popper.js.map +1 -0
- package/public/scripts/power-user.js +571 -0
- package/public/scripts/purify.min.js +3 -0
- package/public/scripts/purify.min.js.map +1 -0
- package/public/scripts/showdown.min.js +3 -0
- package/public/scripts/showdown.min.js.map +1 -0
- package/public/scripts/swiped-events.js +165 -0
- package/public/scripts/textgen-settings.js +194 -0
- package/public/scripts/toolcool-color-picker.js +87 -0
- package/public/scripts/utils.js +109 -0
- package/public/scripts/world-info.js +661 -0
- package/public/sounds/message.mp3 +0 -0
- package/public/style.css +3633 -0
- package/public/webfonts/NotoSans/NotoSans-Black.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Black.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-BlackItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Bold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Bold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-BoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraBoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLight.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ExtraLightItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Italic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Italic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Light.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Light.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-LightItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-LightItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Medium.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Medium.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-MediumItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Regular.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Regular.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBold.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBold.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-SemiBoldItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-Thin.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-Thin.woff2 +0 -0
- package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff +0 -0
- package/public/webfonts/NotoSans/NotoSans-ThinItalic.woff2 +0 -0
- package/public/webfonts/NotoSans/stylesheet.css +162 -0
- package/public/webfonts/fa-solid-900.ttf +0 -0
- package/public/webfonts/fa-solid-900.woff2 +0 -0
- package/readme.md +187 -0
- package/server.js +2593 -0
- package/start.sh +24 -0
- package/tools/charaverter/main.mjs +110 -0
- package/tools/charaverter/package.json +10 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.floating_prompt_settings {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
#extension_floating_counter {
|
|
7
|
+
font-weight: 600;
|
|
8
|
+
color: orange;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.floating_prompt_settings textarea {
|
|
12
|
+
font-size: calc(var(--mainFontSize) * 0.9);
|
|
13
|
+
line-height: 1.2;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.floating_prompt_radio_group {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
}
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { getStringHash, debounce } from "../../utils.js";
|
|
2
|
+
import { getContext, getApiUrl, extension_settings } from "../../extensions.js";
|
|
3
|
+
import { extension_prompt_types, saveSettingsDebounced } from "../../../script.js";
|
|
4
|
+
export { MODULE_NAME };
|
|
5
|
+
|
|
6
|
+
const MODULE_NAME = '1_memory';
|
|
7
|
+
const UPDATE_INTERVAL = 1000;
|
|
8
|
+
|
|
9
|
+
let lastCharacterId = null;
|
|
10
|
+
let lastGroupId = null;
|
|
11
|
+
let lastChatId = null;
|
|
12
|
+
let lastMessageHash = null;
|
|
13
|
+
let lastMessageId = null;
|
|
14
|
+
let inApiCall = false;
|
|
15
|
+
|
|
16
|
+
const formatMemoryValue = (value) => value ? `Context: ${value.trim()}` : '';
|
|
17
|
+
const saveChatDebounced = debounce(() => getContext().saveChat(), 2000);
|
|
18
|
+
|
|
19
|
+
const defaultSettings = {
|
|
20
|
+
minLongMemory: 16,
|
|
21
|
+
maxLongMemory: 1024,
|
|
22
|
+
longMemoryLength: 128,
|
|
23
|
+
shortMemoryLength: 512,
|
|
24
|
+
minShortMemory: 128,
|
|
25
|
+
maxShortMemory: 1024,
|
|
26
|
+
shortMemoryStep: 16,
|
|
27
|
+
longMemoryStep: 8,
|
|
28
|
+
repetitionPenaltyStep: 0.05,
|
|
29
|
+
repetitionPenalty: 1.2,
|
|
30
|
+
maxRepetitionPenalty: 2.0,
|
|
31
|
+
minRepetitionPenalty: 1.0,
|
|
32
|
+
temperature: 1.0,
|
|
33
|
+
minTemperature: 0.1,
|
|
34
|
+
maxTemperature: 2.0,
|
|
35
|
+
temperatureStep: 0.05,
|
|
36
|
+
lengthPenalty: 1,
|
|
37
|
+
minLengthPenalty: -4,
|
|
38
|
+
maxLengthPenalty: 4,
|
|
39
|
+
lengthPenaltyStep: 0.1,
|
|
40
|
+
memoryFrozen: false,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function loadSettings() {
|
|
44
|
+
if (Object.keys(extension_settings.memory).length === 0) {
|
|
45
|
+
Object.assign(extension_settings.memory, defaultSettings);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
$('#memory_long_length').val(extension_settings.memory.longMemoryLength).trigger('input');
|
|
49
|
+
$('#memory_short_length').val(extension_settings.memory.shortMemoryLength).trigger('input');
|
|
50
|
+
$('#memory_repetition_penalty').val(extension_settings.memory.repetitionPenalty).trigger('input');
|
|
51
|
+
$('#memory_temperature').val(extension_settings.memory.temperature).trigger('input');
|
|
52
|
+
$('#memory_length_penalty').val(extension_settings.memory.lengthPenalty).trigger('input');
|
|
53
|
+
$('#memory_frozen').prop('checked', extension_settings.memory.memoryFrozen).trigger('input');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function onMemoryShortInput() {
|
|
57
|
+
const value = $(this).val();
|
|
58
|
+
extension_settings.memory.shortMemoryLength = Number(value);
|
|
59
|
+
$('#memory_short_length_tokens').text(value);
|
|
60
|
+
saveSettingsDebounced();
|
|
61
|
+
|
|
62
|
+
// Don't let long buffer be bigger than short
|
|
63
|
+
if (extension_settings.memory.longMemoryLength > extension_settings.memory.shortMemoryLength) {
|
|
64
|
+
$('#memory_long_length').val(extension_settings.memory.shortMemoryLength).trigger('input');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function onMemoryLongInput() {
|
|
69
|
+
const value = $(this).val();
|
|
70
|
+
extension_settings.memory.longMemoryLength = Number(value);
|
|
71
|
+
$('#memory_long_length_tokens').text(value);
|
|
72
|
+
saveSettingsDebounced();
|
|
73
|
+
|
|
74
|
+
// Don't let long buffer be bigger than short
|
|
75
|
+
if (extension_settings.memory.longMemoryLength > extension_settings.memory.shortMemoryLength) {
|
|
76
|
+
$('#memory_short_length').val(extension_settings.memory.longMemoryLength).trigger('input');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function onMemoryRepetitionPenaltyInput() {
|
|
81
|
+
const value = $(this).val();
|
|
82
|
+
extension_settings.memory.repetitionPenalty = Number(value);
|
|
83
|
+
$('#memory_repetition_penalty_value').text(extension_settings.memory.repetitionPenalty.toFixed(2));
|
|
84
|
+
saveSettingsDebounced();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function onMemoryTemperatureInput() {
|
|
88
|
+
const value = $(this).val();
|
|
89
|
+
extension_settings.memory.temperature = Number(value);
|
|
90
|
+
$('#memory_temperature_value').text(extension_settings.memory.temperature.toFixed(2));
|
|
91
|
+
saveSettingsDebounced();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function onMemoryLengthPenaltyInput() {
|
|
95
|
+
const value = $(this).val();
|
|
96
|
+
extension_settings.memory.lengthPenalty = Number(value);
|
|
97
|
+
$('#memory_length_penalty_value').text(extension_settings.memory.lengthPenalty.toFixed(2));
|
|
98
|
+
saveSettingsDebounced();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function onMemoryFrozenInput() {
|
|
102
|
+
const value = Boolean($(this).prop('checked'));
|
|
103
|
+
extension_settings.memory.memoryFrozen = value;
|
|
104
|
+
saveSettingsDebounced();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function saveLastValues() {
|
|
108
|
+
const context = getContext();
|
|
109
|
+
lastGroupId = context.groupId;
|
|
110
|
+
lastCharacterId = context.characterId;
|
|
111
|
+
lastChatId = context.chatId;
|
|
112
|
+
lastMessageId = context.chat?.length ?? null;
|
|
113
|
+
lastMessageHash = getStringHash((context.chat.length && context.chat[context.chat.length - 1]['mes']) ?? '');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function getLatestMemoryFromChat(chat) {
|
|
117
|
+
if (!Array.isArray(chat) || !chat.length) {
|
|
118
|
+
return '';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const reversedChat = chat.slice().reverse();
|
|
122
|
+
for (let mes of reversedChat) {
|
|
123
|
+
if (mes.extra && mes.extra.memory) {
|
|
124
|
+
return mes.extra.memory;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function moduleWorker() {
|
|
132
|
+
const context = getContext();
|
|
133
|
+
const chat = context.chat;
|
|
134
|
+
|
|
135
|
+
// no characters or group selected
|
|
136
|
+
if (!context.groupId && !context.characterId) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Chat/character/group changed
|
|
141
|
+
if ((context.groupId && lastGroupId !== context.groupId) || (context.characterId !== lastCharacterId) || (context.chatId !== lastChatId)) {
|
|
142
|
+
const latestMemory = getLatestMemoryFromChat(chat);
|
|
143
|
+
setMemoryContext(latestMemory, false);
|
|
144
|
+
saveLastValues();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Currently summarizing or frozen state - skip
|
|
149
|
+
if (inApiCall || extension_settings.memory.memoryFrozen) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// No new messages - do nothing
|
|
154
|
+
if (lastMessageId === chat.length && getStringHash(chat[chat.length - 1].mes) === lastMessageHash) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Messages has been deleted - rewrite the context with the latest available memory
|
|
159
|
+
if (chat.length < lastMessageId) {
|
|
160
|
+
const latestMemory = getLatestMemoryFromChat(chat);
|
|
161
|
+
setMemoryContext(latestMemory, false);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Message has been edited / regenerated - delete the saved memory
|
|
165
|
+
if (chat.length
|
|
166
|
+
&& chat[chat.length - 1].extra
|
|
167
|
+
&& chat[chat.length - 1].extra.memory
|
|
168
|
+
&& lastMessageId === chat.length
|
|
169
|
+
&& getStringHash(chat[chat.length - 1].mes) !== lastMessageHash) {
|
|
170
|
+
delete chat[chat.length - 1].extra.memory;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
await summarizeChat(context);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.log(error);
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
saveLastValues();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function summarizeChat(context) {
|
|
185
|
+
function getMemoryString() {
|
|
186
|
+
return (longMemory + '\n\n' + memoryBuffer.slice().reverse().join('\n\n')).trim();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const chat = context.chat;
|
|
190
|
+
const longMemory = getLatestMemoryFromChat(chat);
|
|
191
|
+
const reversedChat = chat.slice().reverse();
|
|
192
|
+
let memoryBuffer = [];
|
|
193
|
+
|
|
194
|
+
for (let mes of reversedChat) {
|
|
195
|
+
// we reached the point of latest memory
|
|
196
|
+
if (longMemory && mes.extra && mes.extra.memory == longMemory) {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// don't care about system
|
|
201
|
+
if (mes.is_system) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// determine the sender's name
|
|
206
|
+
const name = mes.is_user ? (context.name1 ?? 'You') : (mes.force_avatar ? mes.name : context.name2);
|
|
207
|
+
const entry = `${name}:\n${mes['mes']}`;
|
|
208
|
+
memoryBuffer.push(entry);
|
|
209
|
+
|
|
210
|
+
// check if token limit was reached
|
|
211
|
+
if (context.getTokenCount(getMemoryString()) >= extension_settings.memory.shortMemoryLength) {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const resultingString = getMemoryString();
|
|
217
|
+
|
|
218
|
+
if (context.getTokenCount(resultingString) < extension_settings.memory.shortMemoryLength) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// perform the summarization API call
|
|
223
|
+
try {
|
|
224
|
+
inApiCall = true;
|
|
225
|
+
const url = new URL(getApiUrl());
|
|
226
|
+
url.pathname = '/api/summarize';
|
|
227
|
+
|
|
228
|
+
const apiResult = await fetch(url, {
|
|
229
|
+
method: 'POST',
|
|
230
|
+
headers: {
|
|
231
|
+
'Content-Type': 'application/json',
|
|
232
|
+
'Bypass-Tunnel-Reminder': 'bypass',
|
|
233
|
+
},
|
|
234
|
+
body: JSON.stringify({
|
|
235
|
+
text: resultingString,
|
|
236
|
+
params: {
|
|
237
|
+
min_length: extension_settings.memory.longMemoryLength * 0, // testing how it behaves 0 min length
|
|
238
|
+
max_length: extension_settings.memory.longMemoryLength,
|
|
239
|
+
repetition_penalty: extension_settings.memory.repetitionPenalty,
|
|
240
|
+
temperature: extension_settings.memory.temperature,
|
|
241
|
+
length_penalty: extension_settings.memory.lengthPenalty,
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
if (apiResult.ok) {
|
|
247
|
+
const data = await apiResult.json();
|
|
248
|
+
const summary = data.summary;
|
|
249
|
+
|
|
250
|
+
const newContext = getContext();
|
|
251
|
+
|
|
252
|
+
// something changed during summarization request
|
|
253
|
+
if (newContext.groupId !== context.groupId || newContext.chatId !== context.chatId || (!newContext.groupId && (newContext.characterId !== context.characterId))) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
setMemoryContext(summary, true);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.log(error);
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
inApiCall = false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function onMemoryRestoreClick() {
|
|
269
|
+
const context = getContext();
|
|
270
|
+
const content = $('#memory_contents').val();
|
|
271
|
+
const reversedChat = context.chat.slice().reverse();
|
|
272
|
+
|
|
273
|
+
for (let mes of reversedChat) {
|
|
274
|
+
if (mes.extra && mes.extra.memory == content) {
|
|
275
|
+
delete mes.extra.memory;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const newContent = getLatestMemoryFromChat(context.chat);
|
|
281
|
+
setMemoryContext(newContent, false);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function onMemoryContentInput() {
|
|
285
|
+
const value = $(this).val();
|
|
286
|
+
setMemoryContext(value, true);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function setMemoryContext(value, saveToMessage) {
|
|
290
|
+
const context = getContext();
|
|
291
|
+
context.setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_prompt_types.AFTER_SCENARIO);
|
|
292
|
+
$('#memory_contents').val(value);
|
|
293
|
+
|
|
294
|
+
if (saveToMessage && context.chat.length) {
|
|
295
|
+
const mes = context.chat[context.chat.length - 1];
|
|
296
|
+
|
|
297
|
+
if (!mes.extra) {
|
|
298
|
+
mes.extra = {};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
mes.extra.memory = value;
|
|
302
|
+
saveChatDebounced();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
$(document).ready(function () {
|
|
307
|
+
function addExtensionControls() {
|
|
308
|
+
const settingsHtml = `
|
|
309
|
+
<div id="memory_settings">
|
|
310
|
+
<div class="inline-drawer">
|
|
311
|
+
<div class="inline-drawer-toggle inline-drawer-header">
|
|
312
|
+
<b>Chat memory</b>
|
|
313
|
+
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
|
314
|
+
</div>
|
|
315
|
+
<div class="inline-drawer-content">
|
|
316
|
+
<label for="memory_contents">Memory contents</label>
|
|
317
|
+
<textarea id="memory_contents" class="text_pole" rows="8" placeholder="Context will be generated here..."></textarea>
|
|
318
|
+
<div class="memory_contents_controls">
|
|
319
|
+
<input id="memory_restore" class="menu_button" type="submit" value="Restore previous state" />
|
|
320
|
+
<label for="memory_frozen"><input id="memory_frozen" type="checkbox" /> Freeze context</label>
|
|
321
|
+
</div>
|
|
322
|
+
</div>
|
|
323
|
+
</div>
|
|
324
|
+
<div class="inline-drawer">
|
|
325
|
+
<div class="inline-drawer-toggle inline-drawer-header">
|
|
326
|
+
<b>Summarization parameters</b>
|
|
327
|
+
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
|
|
328
|
+
</div>
|
|
329
|
+
<div class="inline-drawer-content">
|
|
330
|
+
<label for="memory_short_length">Buffer <small>[short-term]</small> length (<span id="memory_short_length_tokens"></span> tokens)</label>
|
|
331
|
+
<input id="memory_short_length" type="range" value="${defaultSettings.shortMemoryLength}" min="${defaultSettings.minShortMemory}" max="${defaultSettings.maxShortMemory}" step="${defaultSettings.shortMemoryStep}" />
|
|
332
|
+
<label for="memory_long_length">Summary <small>[long-term]</small> length (<span id="memory_long_length_tokens"></span> tokens)</label>
|
|
333
|
+
<input id="memory_long_length" type="range" value="${defaultSettings.longMemoryLength}" min="${defaultSettings.minLongMemory}" max="${defaultSettings.maxLongMemory}" step="${defaultSettings.longMemoryStep}" />
|
|
334
|
+
<label for="memory_temperature">Temperature (<span id="memory_temperature_value"></span>)</label>
|
|
335
|
+
<input id="memory_temperature" type="range" value="${defaultSettings.temperature}" min="${defaultSettings.minTemperature}" max="${defaultSettings.maxTemperature}" step="${defaultSettings.temperatureStep}" />
|
|
336
|
+
<label for="memory_repetition_penalty">Repetition penalty (<span id="memory_repetition_penalty_value"></span>)</label>
|
|
337
|
+
<input id="memory_repetition_penalty" type="range" value="${defaultSettings.repetitionPenalty}" min="${defaultSettings.minRepetitionPenalty}" max="${defaultSettings.maxRepetitionPenalty}" step="${defaultSettings.repetitionPenaltyStep}" />
|
|
338
|
+
<label for="memory_length_penalty">Length penalty <small>[higher = longer summaries]</small> (<span id="memory_length_penalty_value"></span>)</label>
|
|
339
|
+
<input id="memory_length_penalty" type="range" value="${defaultSettings.lengthPenalty}" min="${defaultSettings.minLengthPenalty}" max="${defaultSettings.maxLengthPenalty}" step="${defaultSettings.lengthPenaltyStep}" />
|
|
340
|
+
</div>
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
`;
|
|
344
|
+
$('#extensions_settings').append(settingsHtml);
|
|
345
|
+
$('#memory_restore').on('click', onMemoryRestoreClick);
|
|
346
|
+
$('#memory_contents').on('input', onMemoryContentInput);
|
|
347
|
+
$('#memory_long_length').on('input', onMemoryLongInput);
|
|
348
|
+
$('#memory_short_length').on('input', onMemoryShortInput);
|
|
349
|
+
$('#memory_repetition_penalty').on('input', onMemoryRepetitionPenaltyInput);
|
|
350
|
+
$('#memory_temperature').on('input', onMemoryTemperatureInput);
|
|
351
|
+
$('#memory_length_penalty').on('input', onMemoryLengthPenaltyInput);
|
|
352
|
+
$('#memory_frozen').on('input', onMemoryFrozenInput);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
addExtensionControls();
|
|
356
|
+
loadSettings();
|
|
357
|
+
setInterval(moduleWorker, UPDATE_INTERVAL);
|
|
358
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"display_name": "Memory",
|
|
3
|
+
"loading_order": 9,
|
|
4
|
+
"requires": [
|
|
5
|
+
"summarize"
|
|
6
|
+
],
|
|
7
|
+
"optional": [],
|
|
8
|
+
"js": "index.js",
|
|
9
|
+
"css": "style.css",
|
|
10
|
+
"author": "Cohee#1207",
|
|
11
|
+
"version": "1.0.0",
|
|
12
|
+
"homePage": "https://github.com/Cohee1207/SillyTavern"
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#memory_settings {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
#memory_settings textarea {
|
|
7
|
+
font-size: calc(var(--mainFontSize) * 0.9);
|
|
8
|
+
line-height: 1.2;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
#memory_settings input[type="range"] {
|
|
12
|
+
margin-bottom: 20px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#memory_settings label {
|
|
16
|
+
margin-bottom: 10px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
label[for="memory_frozen"] {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
margin: 0 !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
label[for="memory_frozen"] input {
|
|
26
|
+
margin-right: 10px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.memory_contents_controls {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: row;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
}
|