Compare commits

...

49 Commits
1.9.3 ... 1.9.4

Author SHA1 Message Date
Cohee
29d841a50b Bump package version 2023-07-31 12:54:49 +03:00
Cohee
18e6e578dd Merge pull request #834 from ouoertheo/ouoertheo/objective-auto-check-fix 2023-07-31 09:54:22 +03:00
ouoertheo
d5e40e0271 fix for allowing root task as. notify on manual check 2023-07-30 19:15:05 -05:00
Cohee
6b85f10818 Merge pull request #832 from mweldon/kayra-fix-fresh-coffee 2023-07-31 00:57:16 +03:00
Mike Weldon
73ea029acd Fix rep penalty parameter name 2023-07-30 14:14:17 -07:00
Mike Weldon
27c6e5ecff Fix some presets, bad words, rep allowlist, and banned tokens 2023-07-30 14:03:28 -07:00
Cohee
40f466b2c3 Summary plugin improvements: In-chat position, customizable template, force insert after X words 2023-07-30 23:10:37 +03:00
RossAscends
02667d3d1a Merge branch 'staging' of https://github.com/Cohee1207/SillyTavern into staging 2023-07-31 03:37:52 +09:00
RossAscends
9cb70817c7 fix ctrl+up when sys msg is last 2023-07-31 03:37:49 +09:00
Cohee
e172f50d4f Allow /cut 0 2023-07-30 21:35:36 +03:00
Cohee
49f7185c8c #829 Close chat option 2023-07-30 21:35:21 +03:00
RossAscends
638050a3de skill issue 2023-07-31 02:56:39 +09:00
RossAscends
a0f369d100 Merge branch 'staging' of https://github.com/Cohee1207/SillyTavern into staging 2023-07-31 02:41:41 +09:00
RossAscends
f9239c860d Escape hotkey to close panels/popups 2023-07-31 02:41:15 +09:00
Cohee
41a08fed2b Merge pull request #828 from ouoertheo/ouoertheo/objective-qol-improvements 2023-07-30 19:33:02 +03:00
RossAscends
95d43712d3 fix chat bg color when panels hidden 2023-07-31 01:08:24 +09:00
ouoertheo
4f76a8b0ce fix task counter decrement 2023-07-30 09:27:31 -05:00
ouoertheo
3fc2b81433 help text update 2023-07-30 09:19:17 -05:00
ouoertheo
23a514bba8 full templating for all prompts. prompt mgmt 2023-07-30 09:15:12 -05:00
Cohee1207
51449c4913 Rename Settings option 2023-07-30 16:40:45 +03:00
Cohee1207
18bb362578 Merge branch 'staging' of http://github.com/cohee1207/SillyTavern into staging 2023-07-30 16:38:50 +03:00
Cohee
6d9c2ec365 Merge pull request #819 from pyrater/staging
Show / Hide Top Bar
2023-07-30 16:38:44 +03:00
Cohee
ad26a1968b Merge pull request #818 from city-unit/feature/WI
Add optional alerting for WI debugging.
2023-07-30 16:29:33 +03:00
Cohee1207
52289acc62 Reformat index.html 2023-07-30 16:28:55 +03:00
Cohee1207
b970c69844 Merge branch 'staging' of http://github.com/cohee1207/SillyTavern into staging 2023-07-30 16:28:25 +03:00
Cohee
c8e456d773 Merge pull request #827 from Ahbahl/staging
Moves Claude Assistant prefill box below JB
2023-07-30 16:28:19 +03:00
Cohee1207
d00fbacec3 #822 Increase instruct sequences max lengths 2023-07-30 16:27:29 +03:00
Cohee1207
ccbec7715a #825 Set temperature slider min value to 0.0 2023-07-30 16:21:01 +03:00
Cohee1207
1b7973ec13 Merge branch 'staging' of http://github.com/cohee1207/SillyTavern into staging 2023-07-30 16:20:05 +03:00
Ahbahl
1f63fd9344 Moves Claude Assistant prefill below JB to be more in line with how prompts are structured. 2023-07-30 15:13:10 +02:00
joe
d8d5118283 removed padding 2023-07-30 11:57:21 +09:00
joe
11226ff7d6 add CSS to round corners 2023-07-30 11:56:17 +09:00
pyrater
844d9c86a4 Merge branch 'SillyTavern:staging' into staging 2023-07-30 11:50:09 +09:00
joe
0aee97ccca Added Option to toggle/Hide settings bar. 2023-07-30 11:47:17 +09:00
city-unit
fa06e5ee5a Add optional alerting for WI debugging. 2023-07-29 22:15:54 -04:00
Cohee
6794be4d1e Merge branch 'release' into staging 2023-07-30 03:10:12 +03:00
Cohee
4316396880 Update readme 2023-07-30 03:09:55 +03:00
Cohee
fd93bc7736 Merge pull request #817 from city-unit/feature/activechat
Persist active chat across devices.
2023-07-30 03:07:55 +03:00
city-unit
0cc88c17c7 Handle groups correctly, save settings. 2023-07-29 20:05:12 -04:00
city-unit
6829f5308f Persist active chat across devices. 2023-07-29 19:48:08 -04:00
Mike Weldon
1689913b43 Fix minor typo that broke phraseRepPen for NAI 2023-07-30 02:35:05 +03:00
Cohee
33b7e8fad1 Merge branch 'release' into staging 2023-07-30 02:33:48 +03:00
Cohee
17eb55731e Merge pull request #816 from mweldon/kayra-fix
Phrase Rep Pen typo fix
2023-07-30 02:32:18 +03:00
Mike Weldon
9dba57dc85 Fix minor typo that broke phraseRepPen for NAI 2023-07-29 15:59:18 -07:00
Cohee
dddc49c235 #798 Claude assistant prefill 2023-07-30 01:51:59 +03:00
RossAscends
faf9c4445f Create Default QR preset 2023-07-30 06:26:06 +09:00
RossAscends
a646aaa125 Merge branch 'staging' of https://github.com/Cohee1207/SillyTavern into staging 2023-07-30 06:22:05 +09:00
RossAscends
80a0cb2bc4 MPV of QuickReply Presets 2023-07-30 06:22:03 +09:00
Cohee1207
ac4fa0e035 Merge branch 'staging' of http://github.com/cohee1207/SillyTavern into staging 2023-07-29 21:18:56 +03:00
33 changed files with 668 additions and 491 deletions

View File

@@ -291,7 +291,6 @@ SillyTavern 会将 API 密钥保存在目录中的 `secrets.json` 文件内。
* RossAscends' additions: AGPL v3
* Portions of CncAnon's TavernAITurbo mod: Unknown license
* kingbri's various commits and suggestions (https://github.com/bdashore3)
* BlipRanger's miscellaneous UI & extension modifications (https://github.com/BlipRanger)
* Waifu mode inspired by the work of PepperTaco (https://github.com/peppertaco/Tavern/)
* Thanks Pygmalion University for being awesome testers and suggesting cool features!
* Thanks oobabooga for compiling presets for TextGen
@@ -303,4 +302,4 @@ SillyTavern 会将 API 密钥保存在目录中的 `secrets.json` 文件内。
* Thanks paniphons for providing a FAQ document
* 10K Discord Users Celebratory Background by @kallmeflocc
* Default content (characters and lore books) provided by @OtisAlejandro, @RossAscends and @kallmeflocc
* Korean translation by @doloroushyeonse
* Korean translation by @doloroushyeonse

1
.github/readme.md vendored
View File

@@ -293,7 +293,6 @@ GNU Affero General Public License for more details.**
* RossAscends' additions: AGPL v3
* Portions of CncAnon's TavernAITurbo mod: Unknown license
* kingbri's various commits and suggestions (<https://github.com/bdashore3>)
* BlipRanger's miscellaneous UI & extension modifications (<https://github.com/BlipRanger>)
* Waifu mode inspired by the work of PepperTaco (<https://github.com/peppertaco/Tavern/>)
* Thanks Pygmalion University for being awesome testers and suggesting cool features!
* Thanks oobabooga for compiling presets for TextGen

1
.gitignore vendored
View File

@@ -26,4 +26,5 @@ secrets.json
/dist
/backups/
public/movingUI/
public/QuickReplies/
content.log

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "sillytavern",
"version": "1.9.3",
"version": "1.9.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sillytavern",
"version": "1.9.3",
"version": "1.9.4",
"license": "AGPL-3.0",
"dependencies": {
"@dqbd/tiktoken": "^1.0.2",

View File

@@ -51,7 +51,7 @@
"type": "git",
"url": "https://github.com/SillyTavern/SillyTavern.git"
},
"version": "1.9.3",
"version": "1.9.4",
"scripts": {
"start": "node server.js",
"pkg": "pkg --compress Gzip --no-bytecode --public ."

View File

@@ -13,6 +13,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "aggressive",
"max_context": 8192
}

View File

@@ -15,6 +15,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "aggressive",
"max_context": 8192
}

View File

@@ -1,23 +0,0 @@
{
"order": [
1,
3,
4,
0,
2
],
"temperature": 1.05,
"max_length": 90,
"min_length": 1,
"tail_free_sampling": 0.989,
"repetition_penalty": 1.5,
"repetition_penalty_range": 8192,
"repetition_penalty_frequency": 0.03,
"repetition_penalty_presence": 0.005,
"repetition_penalty_slope": 0,
"top_a": 0.075,
"top_k": 79,
"top_p": 0.95,
"typical_p": 1,
"max_context": 8192
}

View File

@@ -15,6 +15,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 8192
}

View File

@@ -16,5 +16,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 8192
}

View File

@@ -1,5 +1,5 @@
{
"order": [6, 0, 1, 2, 3],
"order": [0, 1, 2, 3],
"temperature": 1,
"max_length": 300,
"min_length": 1,
@@ -14,6 +14,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "off",
"max_context": 8192
}

View File

@@ -16,5 +16,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 8192
}

View File

@@ -16,5 +16,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 8192
}

View File

@@ -16,6 +16,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 8192
}

View File

@@ -16,5 +16,7 @@
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"cfg_scale": 1,
"phrase_rep_pen": "very_light",
"max_context": 8192
}

View File

@@ -0,0 +1,23 @@
{
"name": "Default",
"quickReplyEnabled": true,
"quickReplySlots": [
{
"mes": "/?",
"label": "HELP",
"enabled": true
},
{
"mes": "/newchat",
"label": "New Chat",
"enabled": true
},
{
"mes": "/bgcol",
"label": "Match UI to Background",
"enabled": true
}
],
"numberOfSlots": 3,
"selectedPreset": "Default"
}

View File

@@ -253,7 +253,7 @@
</div>
<div class="range-block-range-and-counter">
<div class="range-block-range">
<input type="range" id="temp" name="volume" min="0.1" max="2.0" step="0.01">
<input type="range" id="temp" name="volume" min="0.0" max="2.0" step="0.01">
</div>
<div class="range-block-counter">
<div contenteditable="true" data-for="temp" id="temp_counter">
@@ -1319,6 +1319,14 @@
<textarea id="jailbreak_prompt_textarea" class="text_pole textarea_compact" name="jailbreak_prompt" rows="6" placeholder=""></textarea>
</div>
</div>
<div class="range-block" data-source="claude">
<div class="range-block-title" data-i18n="Assistant Prefill">
Assistant Prefill
</div>
<div class="wide100p">
<input type="text" id="claude_assistant_prefill" class="text_pole" placeholder="Start Claude's answer with...">
</div>
</div>
<div class="inline-drawer wide100p">
<div class="inline-drawer-toggle inline-drawer-header margin-bot-10px">
@@ -1863,7 +1871,7 @@
<span data-i18n="Input Sequence">Input Sequence</span>
</label>
<div>
<input id="instruct_input_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
<input id="instruct_input_sequence" class="text_pole textarea_compact" type="text" maxlength="500" />
</div>
</div>
<div class="flex1">
@@ -1871,7 +1879,7 @@
<span data-i18n="Output Sequence">Output Sequence</span>
</label>
<div>
<input id="instruct_output_sequence" class="text_pole wide100p textarea_compact" type="text" maxlength="100" />
<input id="instruct_output_sequence" class="text_pole wide100p textarea_compact" type="text" maxlength="500" />
</div>
</div>
</div>
@@ -1881,7 +1889,7 @@
<small data-i18n="System Sequence">System Sequence</small>
</label>
<div>
<input id="instruct_system_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
<input id="instruct_system_sequence" class="text_pole textarea_compact" type="text" maxlength="500" />
</div>
</div>
<div class="flex1">
@@ -1889,7 +1897,7 @@
<small data-i18n="Stop Sequence">Stop Sequence</small>
</label>
<div>
<input id="instruct_stop_sequence" class="text_pole wide100p textarea_compact" type="text" maxlength="100" />
<input id="instruct_stop_sequence" class="text_pole wide100p textarea_compact" type="text" maxlength="500" />
</div>
</div>
<div class="flex1">
@@ -1897,7 +1905,7 @@
<small data-i18n="Separator">Separator</small>
</label>
<div>
<input id="instruct_separator_sequence" class="text_pole wide100p textarea_compact" type="text" maxlength="100" />
<input id="instruct_separator_sequence" class="text_pole wide100p textarea_compact" type="text" maxlength="500" />
</div>
</div>
</div>
@@ -2137,6 +2145,14 @@
Match whole words
</small>
</label>
<label title="Alert if your world info is greater than the allocated budget."
data-i18n="[title]Alert if your world info is greater than the allocated budget."
class="checkbox_label">
<input id="world_info_overflow_alert" type="checkbox" />
<small data-i18n="Alert On Overflow">
Alert On Overflow
</small>
</label>
</div>
</div>
@@ -3766,6 +3782,14 @@
<!-- popups live outside sheld to avoid blur conflicts -->
<div id="options" class="font-family-reset" style="display: none;">
<div class="options-content">
<a id="option_close_chat">
<i class="fa-lg fa-solid fa-times"></i>
<span data-i18n="Close chat">Close chat</span>
</a>
<a id="option_settings">
<i class="fa-lg fa-solid fa-cog"></i>
<span data-i18n="Toggle Panels">Toggle Panels</span>
</a>
<a id="option_toggle_AN">
<i class="fa-lg fa-solid fa-note-sticky"></i>
<span data-i18n="Author's Note">Author's Note</span>

View File

@@ -26,6 +26,7 @@ import {
getWorldInfoPrompt,
setWorldInfoSettings,
world_info_recursive,
world_info_overflow_alert,
world_info_case_sensitive,
world_info_match_whole_words,
world_names,
@@ -737,6 +738,9 @@ let token;
var PromptArrayItemForRawPromptDisplay;
export let active_character = ""
export let active_group = ""
export function getRequestHeaders() {
return {
"Content-Type": "application/json",
@@ -786,6 +790,14 @@ function checkOnlineStatus() {
}
}
export function setActiveCharacter(character) {
active_character = character;
}
export function setActiveGroup(group) {
active_group = group;
}
async function getStatus() {
if (is_get_status) {
if (main_api == "koboldhorde") {
@@ -5009,6 +5021,10 @@ async function getSettings(type) {
highlightSelectedAvatar();
setPersonaDescription();
//Load the active character and group
active_character = settings.active_character;
active_group = settings.active_group;
//Load the API server URL from settings
api_server = settings.api_server;
$("#api_url_text").val(api_server);
@@ -5049,6 +5065,8 @@ async function saveSettings(type) {
data: JSON.stringify({
firstRun: firstRun,
username: name1,
active_character: active_character,
active_group: active_group,
api_server: api_server,
api_server_textgenerationwebui: api_server_textgenerationwebui,
preset_settings: preset_settings,
@@ -5060,6 +5078,7 @@ async function saveSettings(type) {
world_info_depth: world_info_depth,
world_info_budget: world_info_budget,
world_info_recursive: world_info_recursive,
world_info_overflow_alert: world_info_overflow_alert,
world_info_case_sensitive: world_info_case_sensitive,
world_info_match_whole_words: world_info_match_whole_words,
world_info_character_strategy: world_info_character_strategy,
@@ -7732,6 +7751,51 @@ $(document).ready(function () {
else if (id == "option_delete_mes") {
setTimeout(openMessageDelete, animation_duration);
}
else if (id == "option_close_chat") {
if (is_send_press == false) {
clearChat();
chat.length = 0;
resetSelectedGroup();
setCharacterId(undefined);
setCharacterName('');
setActiveCharacter(null);
setActiveGroup(null);
this_edit_mes_id = undefined;
chat_metadata = {};
selected_button = "characters";
$("#rm_button_selected_ch").children("h2").text('');
select_rm_characters();
sendSystemMessage(system_message_types.WELCOME);
} else {
toastr.info("Please stop the message generation first.");
}
}
else if (id === "option_settings") {
//var checkBox = document.getElementById("waifuMode");
var topBar = document.getElementById("top-bar");
var topSettingsHolder = document.getElementById("top-settings-holder");
var divchat = document.getElementById("chat");
//if (checkBox.checked) {
if (topBar.style.display === "none") {
topBar.style.display = ""; // or "inline-block" if that's the original display value
topSettingsHolder.style.display = ""; // or "inline-block" if that's the original display value
divchat.style.borderRadius = "";
divchat.style.backgroundColor = "";
} else {
divchat.style.borderRadius = "10px"; // Adjust the value to control the roundness of the corners
divchat.style.backgroundColor = ""; // Set the background color to your preference
topBar.style.display = "none";
topSettingsHolder.style.display = "none";
}
//}
}
hideMenu();
});

View File

@@ -13,6 +13,10 @@ import {
menu_type,
max_context,
saveSettingsDebounced,
active_group,
active_character,
setActiveGroup,
setActiveCharacter,
} from "../script.js";
import {
@@ -330,11 +334,21 @@ export function RA_CountCharTokens() {
characterStatsHandler(characters, this_chid);
});
}
//Auto Load Last Charcter -- (fires when active_character is defined and auto_load_chat is true)
/**
* Auto load chat with the last active character or group.
* Fires when active_character is defined and auto_load_chat is true.
* The function first tries to find a character with a specific ID from the global settings.
* If it doesn't exist, it tries to find a group with a specific grid from the global settings.
* If the character list hadn't been loaded yet, it calls itself again after 100ms delay.
* The character or group is selected (clicked) if it is found.
*/
async function RA_autoloadchat() {
if (document.getElementById('CharID0') !== null) {
var charToAutoLoad = document.getElementById('CharID' + LoadLocal('ActiveChar'));
let groupToAutoLoad = document.querySelector(`.group_select[grid="${LoadLocal('ActiveGroup')}"]`);
// active character is the name, we should look it up in the character list and get the id
let active_character_id = Object.keys(characters).find(key => characters[key].avatar === active_character);
var charToAutoLoad = document.getElementById('CharID' + active_character_id);
let groupToAutoLoad = document.querySelector(`.group_select[grid="${active_group}"]`);
if (charToAutoLoad != null) {
$(charToAutoLoad).click();
}
@@ -342,7 +356,7 @@ async function RA_autoloadchat() {
$(groupToAutoLoad).click();
}
// if the charcter list hadn't been loaded yet, try again.
// if the character list hadn't been loaded yet, try again.
} else { setTimeout(RA_autoloadchat, 100); }
}
@@ -903,16 +917,22 @@ $("document").ready(function () {
$("#rm_button_characters").click(function () { SaveLocal('SelectedNavTab', 'rm_button_characters'); });
// when a char is selected from the list, save them as the auto-load character for next page load
// when a char is selected from the list, save their name as the auto-load character for next page load
$(document).on("click", ".character_select", function () {
SaveLocal('ActiveChar', $(this).attr('chid'));
SaveLocal('ActiveGroup', null);
setActiveCharacter($(this).find('.avatar').attr('title'));
setActiveGroup(null);
saveSettingsDebounced();
});
$(document).on("click", ".group_select", function () {
SaveLocal('ActiveChar', null);
SaveLocal('ActiveGroup', $(this).data('id'));
setActiveCharacter(null);
setActiveGroup($(this).data('id'));
saveSettingsDebounced();
});
//this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
$('#send_textarea').on('input', function () {
this.style.height = '40px';
@@ -1028,11 +1048,10 @@ $("document").ready(function () {
}
if (event.ctrlKey && event.key == "ArrowUp") { //edits last USER message if chatbar is empty and focused
console.debug('got ctrl+uparrow input');
if (
$("#send_textarea").val() === '' &&
chatbarInFocus === true &&
$(".swipe_right:last").css('display') === 'flex' &&
($(".swipe_right:last").css('display') === 'flex' || $('.last_mes').attr('is_system') === 'true') &&
$("#character_popup").css("display") === "none" &&
$("#shadow_select_chat_popup").css("display") === "none"
) {
@@ -1040,7 +1059,7 @@ $("document").ready(function () {
const lastIsUserMes = isUserMesList[isUserMesList.length - 1];
const editMes = lastIsUserMes.querySelector('.mes_block .mes_edit');
if (editMes !== null) {
$(editMes).click();
$(editMes).trigger('click');
}
}
}
@@ -1061,5 +1080,59 @@ $("document").ready(function () {
}
}
}
if (event.key == "Escape") { //closes various panels
if ($("#curEditTextarea").is(":visible")) {
return
}
if ($("#dialogue_popup").is(":visible")) {
if ($("#dialogue_popup_cancel").is(":visible")) {
$("#dialogue_popup_cancel").trigger('click');
return
} else {
$("#dialogue_popup_ok").trigger('click')
return
}
}
if ($("#select_chat_popup").is(":visible")) {
$("#select_chat_cross").trigger('click');
return
}
if ($("#character_popup").is(":visible")) {
$("#character_cross").trigger('click');
return
}
if ($(".drawer-content")
.not('#WorldInfo')
.not('#left-nav-panel')
.not('#right-nav-panel')
.is(":visible")) {
let visibleDrawerContent = $(".drawer-content:visible")
.not('#WorldInfo')
.not('#left-nav-panel')
.not('#right-nav-panel')
$(visibleDrawerContent).parent().find('.drawer-icon').trigger('click');
return
}
if ($("#floatingPrompt").is(":visible")) {
$("#ANClose").trigger('click');
return
}
if ($("#WorldInfo").is(":visible")) {
$("#WIDrawerIcon").trigger('click');
return
}
if ($("#left-nav-panel").is(":visible")) {
$("#leftNavDrawerIcon").trigger('click');
return
}
if ($("#right-nav-panel").is(":visible")) {
$("#rightNavDrawerIcon").trigger('click');
return
}
}
}
});

View File

@@ -1,4 +1,4 @@
import { getStringHash, debounce, waitUntilCondition } from "../../utils.js";
import { getStringHash, debounce, waitUntilCondition, extractAllWords } from "../../utils.js";
import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules } from "../../extensions.js";
import { eventSource, event_types, extension_prompt_types, generateQuietPrompt, is_send_press, saveSettingsDebounced, substituteParams } from "../../../script.js";
export { MODULE_NAME };
@@ -12,7 +12,21 @@ let lastMessageHash = null;
let lastMessageId = null;
let inApiCall = false;
const formatMemoryValue = (value) => value ? `Summary: ${value.trim()}` : '';
const formatMemoryValue = function (value) {
if (!value) {
return '';
}
value = value.trim();
if (extension_settings.memory.template) {
let result = extension_settings.memory.template.replace(/{{summary}}/i, value);
return substituteParams(result);
} else {
return `Summary: ${value}`;
}
}
const saveChatDebounced = debounce(() => getContext().saveChat(), 2000);
const summary_sources = {
@@ -21,6 +35,7 @@ const summary_sources = {
};
const defaultPrompt = '[Pause your roleplay. Summarize the most important facts and events that have happened in the chat so far. If a summary already exists in your memory, use that as a base and expand with new facts. Limit the summary to {{words}} words or less. Your response should include nothing but the summary.]';
const defaultTemplate = '[Summary: {{summary}}]';
const defaultSettings = {
minLongMemory: 16,
@@ -46,6 +61,9 @@ const defaultSettings = {
memoryFrozen: false,
source: summary_sources.extras,
prompt: defaultPrompt,
template: defaultTemplate,
position: extension_prompt_types.AFTER_SCENARIO,
depth: 2,
promptWords: 200,
promptMinWords: 25,
promptMaxWords: 1000,
@@ -54,6 +72,10 @@ const defaultSettings = {
promptMinInterval: 1,
promptMaxInterval: 100,
promptIntervalStep: 1,
promptForceWords: 0,
promptForceWordsStep: 100,
promptMinForceWords: 0,
promptMaxForceWords: 10000,
};
function loadSettings() {
@@ -61,20 +83,10 @@ function loadSettings() {
Object.assign(extension_settings.memory, defaultSettings);
}
if (extension_settings.memory.source === undefined) {
extension_settings.memory.source = defaultSettings.source;
}
if (extension_settings.memory.prompt === undefined) {
extension_settings.memory.prompt = defaultSettings.prompt;
}
if (extension_settings.memory.promptWords === undefined) {
extension_settings.memory.promptWords = defaultSettings.promptWords;
}
if (extension_settings.memory.promptInterval === undefined) {
extension_settings.memory.promptInterval = defaultSettings.promptInterval;
for (const key of Object.keys(defaultSettings)) {
if (extension_settings.memory[key] === undefined) {
extension_settings.memory[key] = defaultSettings[key];
}
}
$('#summary_source').val(extension_settings.memory.source).trigger('change');
@@ -87,6 +99,10 @@ function loadSettings() {
$('#memory_prompt').val(extension_settings.memory.prompt).trigger('input');
$('#memory_prompt_words').val(extension_settings.memory.promptWords).trigger('input');
$('#memory_prompt_interval').val(extension_settings.memory.promptInterval).trigger('input');
$('#memory_template').val(extension_settings.memory.template).trigger('input');
$('#memory_depth').val(extension_settings.memory.depth).trigger('input');
$(`input[name="memory_position"][value="${extension_settings.memory.position}"]`).prop('checked', true).trigger('input');
$('#memory_prompt_words_force').val(extension_settings.memory.promptForceWords).trigger('input');
}
function onSummarySourceChange(event) {
@@ -170,6 +186,31 @@ function onMemoryPromptInput() {
saveSettingsDebounced();
}
function onMemoryTemplateInput() {
const value = $(this).val();
extension_settings.memory.template = value;
saveSettingsDebounced();
}
function onMemoryDepthInput() {
const value = $(this).val();
extension_settings.memory.depth = Number(value);
saveSettingsDebounced();
}
function onMemoryPositionChange(e) {
const value = e.target.value;
extension_settings.memory.position = value;
saveSettingsDebounced();
}
function onMemoryPromptWordsForceInput() {
const value = $(this).val();
extension_settings.memory.promptForceWords = Number(value);
$('#memory_prompt_words_force_value').text(extension_settings.memory.promptForceWords);
saveSettingsDebounced();
}
function saveLastValues() {
const context = getContext();
lastGroupId = context.groupId;
@@ -310,19 +351,30 @@ async function summarizeChatMain(context, force) {
}
let messagesSinceLastSummary = 0;
let wordsSinceLastSummary = 0;
let conditionSatisfied = false;
for (let i = context.chat.length - 1; i >= 0; i--) {
if (context.chat[i].extra && context.chat[i].extra.memory) {
break;
}
messagesSinceLastSummary++;
wordsSinceLastSummary += extractAllWords(context.chat[i].mes).length;
}
if (messagesSinceLastSummary < extension_settings.memory.promptInterval && !force) {
console.debug(`Not enough messages since last summary (messages: ${messagesSinceLastSummary}, interval: ${extension_settings.memory.promptInterval}`);
if (messagesSinceLastSummary >= extension_settings.memory.promptInterval) {
conditionSatisfied = true;
}
if (extension_settings.memory.promptForceWords && wordsSinceLastSummary >= extension_settings.memory.promptForceWords) {
conditionSatisfied = true;
}
if (!conditionSatisfied && !force) {
console.debug(`Summary conditions not satisfied (messages: ${messagesSinceLastSummary}, interval: ${extension_settings.memory.promptInterval}, words: ${wordsSinceLastSummary}, force words: ${extension_settings.memory.promptForceWords})`);
return;
}
console.log('Summarizing chat, messages since last summary: ' + messagesSinceLastSummary);
console.log('Summarizing chat, messages since last summary: ' + messagesSinceLastSummary, 'words since last summary: ' + wordsSinceLastSummary);
const prompt = substituteParams(extension_settings.memory.prompt)
.replace(/{{words}}/gi, extension_settings.memory.promptWords);
@@ -458,9 +510,11 @@ function onMemoryContentInput() {
function setMemoryContext(value, saveToMessage) {
const context = getContext();
context.setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_prompt_types.AFTER_SCENARIO);
context.setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_settings.memory.position, extension_settings.memory.depth);
$('#memory_contents').val(value);
console.log('Memory set to: ' + value);
console.log('Summary set to: ' + value);
console.debug('Position: ' + extension_settings.memory.position);
console.debug('Depth: ' + extension_settings.memory.depth);
if (saveToMessage && context.chat.length) {
const idx = context.chat.length - 2;
@@ -496,6 +550,21 @@ jQuery(function () {
<input id="memory_restore" class="menu_button" type="button" value="Restore previous state" />
<label for="memory_frozen"><input id="memory_frozen" type="checkbox" />Pause summarization</label>
</div>
<div class="memory_template">
<label for="memory_template">Injection template:</label>
<textarea id="memory_template" class="text_pole textarea_compact" rows="1" placeholder="Use {{summary}} macro to specify the position of summarized text."></textarea>
</div>
<label for="memory_position">Injection position:</label>
<div class="radio_group">
<label>
<input type="radio" name="memory_position" value="0" />
After scenario
</label>
<label>
<input type="radio" name="memory_position" value="1" />
In-chat @ Depth <input id="memory_depth" class="text_pole widthUnset" type="number" min="0" max="99" />
</label>
</div>
<div data-source="main" class="memory_contents_controls">
</div>
<div data-source="main">
@@ -511,6 +580,9 @@ jQuery(function () {
<input id="memory_prompt_words" type="range" value="${defaultSettings.promptWords}" min="${defaultSettings.promptMinWords}" max="${defaultSettings.promptMaxWords}" step="${defaultSettings.promptWordsStep}" />
<label for="memory_prompt_interval">Update interval (<span id="memory_prompt_interval_value"></span> messages)</label>
<input id="memory_prompt_interval" type="range" value="${defaultSettings.promptInterval}" min="${defaultSettings.promptMinInterval}" max="${defaultSettings.promptMaxInterval}" step="${defaultSettings.promptIntervalStep}" />
<label for="memory_prompt_words_force">Force update after (<span id="memory_prompt_words_force_value"></span> words)</label>
<small>Set to 0 to disable</small>
<input id="memory_prompt_words_force" type="range" value="${defaultSettings.promptForceWords}" min="${defaultSettings.promptMinForceWords}" max="${defaultSettings.promptMaxForceWords}" step="${defaultSettings.promptForceWordsStep}" />
</div>
<div data-source="extras">
<label for="memory_short_length">Chat to Summarize buffer length (<span id="memory_short_length_tokens"></span> tokens)</label>
@@ -542,6 +614,10 @@ jQuery(function () {
$('#memory_prompt_interval').on('input', onMemoryPromptIntervalInput);
$('#memory_prompt').on('input', onMemoryPromptInput);
$('#memory_force_summarize').on('click', forceSummarizeChat);
$('#memory_template').on('input', onMemoryTemplateInput);
$('#memory_depth').on('input', onMemoryDepthInput);
$('input[name="memory_position"]').on('change', onMemoryPositionChange);
$('#memory_prompt_words_force').on('input', onMemoryPromptWordsForceInput);
}
addExtensionControls();

View File

@@ -1,34 +1,26 @@
#memory_settings {
display: flex;
flex-direction: column;
}
#memory_settings textarea {
font-size: calc(var(--mainFontSize) * 0.9);
line-height: 1.2;
}
#memory_settings input[type="range"] {
margin-bottom: 20px;
}
#memory_settings label {
margin-bottom: 10px;
}
label[for="memory_frozen"] {
display: flex;
align-items: center;
margin: 0 !important;
}
label[for="memory_frozen"] input {
margin-right: 10px;
}
.memory_contents_controls {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
#memory_settings {
display: flex;
flex-direction: column;
}
#memory_settings textarea {
font-size: calc(var(--mainFontSize) * 0.9);
line-height: 1.2;
}
label[for="memory_frozen"] {
display: flex;
align-items: center;
margin: 0 !important;
}
label[for="memory_frozen"] input {
margin-right: 10px;
}
.memory_contents_controls {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}

View File

@@ -69,14 +69,21 @@ function getTaskByIdRecurse(taskId, task) {
return null;
}
function substituteParamsPrompts(content) {
content = content.replace(/{{objective}}/gi, currentObjective.description)
content = content.replace(/{{task}}/gi, currentTask.description)
content = substituteParams(content)
return content
}
// Call Quiet Generate to create task list using character context, then convert to tasks. Should not be called much.
async function generateTasks() {
const prompt = substituteParams(objectivePrompts.createTask.replace(/{{objective}}/gi, currentObjective.description));
const prompt = substituteParamsPrompts(objectivePrompts.createTask);
console.log(`Generating tasks for objective with prompt`)
toastr.info('Generating tasks for objective', 'Please wait...');
const taskResponse = await generateQuietPrompt(prompt)
// Clear all existing objective tasks when generating
currentObjective.children = []
const numberedListPattern = /^\d+\./
@@ -100,8 +107,9 @@ async function checkTaskCompleted() {
return
}
checkCounter = $('#objective-check-frequency').val()
toastr.info("Checking for task completion.")
const prompt = substituteParams(objectivePrompts.checkTaskCompleted.replace(/{{task}}/gi, currentTask.description));
const prompt = substituteParamsPrompts(objectivePrompts.checkTaskCompleted);
const taskResponse = (await generateQuietPrompt(prompt)).toLowerCase()
// Check response if task complete
@@ -116,8 +124,10 @@ async function checkTaskCompleted() {
}
function getNextIncompleteTaskRecurse(task){
// Skip tasks with children, as they will have subtasks to determine completeness
if (task.completed === false && task.children.length === 0){
if (task.completed === false // Return task if incomplete
&& task.children.length === 0 // Ensure task has no children, it's subtasks will determine completeness
&& task.parentId // Must have parent id. Only root task will be missing this and we dont want that
){
return task
}
for (const childTask of task.children) {
@@ -149,7 +159,7 @@ function setCurrentTask(taskId = null) {
// Don't just check for a current task, check if it has data
const description = currentTask.description || null;
if (description) {
const extensionPromptText = objectivePrompts.currentTask.replace(/{{task}}/gi, description);
const extensionPromptText = substituteParamsPrompts(objectivePrompts.currentTask);
// Remove highlights
$('.objective-task').css({'border-color':'','border-width':''})
@@ -163,7 +173,6 @@ function setCurrentTask(taskId = null) {
highlightTask = parent
}
// Update the extension prompt
context.setExtensionPrompt(MODULE_NAME, extensionPromptText, 1, $('#objective-chat-depth').val());
console.info(`Current task in context.extensionPrompts.Objective is ${JSON.stringify(context.extensionPrompts.Objective)}`);
@@ -369,6 +378,8 @@ function onEditPromptClick() {
let popupText = ''
popupText += `
<div class="objective_prompt_modal">
<small>Edit prompts used by Objective for this session. You can use {{objective}} or {{task}} plus any other standard template variables. Save template to persist changes.</small>
<br>
<div>
<label for="objective-prompt-generate">Generation Prompt</label>
<textarea id="objective-prompt-generate" type="text" class="text_pole textarea_compact" rows="8"></textarea>
@@ -378,12 +389,12 @@ function onEditPromptClick() {
<textarea id="objective-prompt-extension-prompt" type="text" class="text_pole textarea_compact" rows="8"></textarea>
</div>
<div class="objective_prompt_block">
<input id="objective-custom-prompt-name" style="flex-grow:2" type="text" class="flex1 heightFitContent text_pole widthNatural" maxlength="250" placeholder="Custom Prompt Name">
<input id="objective-custom-prompt-save" style="flex-grow:1" class="menu_button" type="submit" value="Save Prompt" />
<label for="objective-custom-prompt-select">Custom Prompt Select</label>
<select id="objective-custom-prompt-select"><select>
</div>
<div class="objective_prompt_block">
<label for="objective-prompt-load">Load Prompt</label>
<select id="objective-prompt-load"><select>
<input id="objective-custom-prompt-new" class="menu_button" type="submit" value="New Prompt" />
<input id="objective-custom-prompt-save" class="menu_button" type="submit" value="Save Prompt" />
<input id="objective-custom-prompt-delete" class="menu_button" type="submit" value="Delete Prompt" />
</div>
</div>`
@@ -405,23 +416,28 @@ function onEditPromptClick() {
$('#objective-prompt-extension-prompt').on('input', () => {
objectivePrompts.currentTask = $('#objective-prompt-extension-prompt').val()
})
// Handle new
$('#objective-custom-prompt-new').on('click', () => {
newCustomPrompt()
})
// Handle save
$('#objective-custom-prompt-save').on('click', () => {
saveCustomPrompt($('#objective-custom-prompt-name').val(), objectivePrompts)
saveCustomPrompt()
})
// Handle delete
$('#objective-custom-prompt-delete').on('click', () => {
const optionSelected = $("#objective-prompt-load").find(':selected').val()
deleteCustomPrompt(optionSelected)
deleteCustomPrompt()
})
// Handle load
$('#objective-prompt-load').on('change', loadCustomPrompt)
$('#objective-custom-prompt-select').on('change', loadCustomPrompt)
}
function saveCustomPrompt(customPromptName, customPrompts) {
async function newCustomPrompt() {
const customPromptName = await callPopup('<h3>Custom Prompt name:</h3>', 'input');
if (customPromptName == "") {
toastr.warning("Please set custom prompt name to save.")
return
@@ -431,12 +447,25 @@ function saveCustomPrompt(customPromptName, customPrompts) {
return
}
extension_settings.objective.customPrompts[customPromptName] = {}
Object.assign(extension_settings.objective.customPrompts[customPromptName], customPrompts)
Object.assign(extension_settings.objective.customPrompts[customPromptName], objectivePrompts)
saveSettingsDebounced()
populateCustomPrompts()
}
function deleteCustomPrompt(customPromptName){
function saveCustomPrompt() {
const customPromptName = $("#objective-custom-prompt-select").find(':selected').val()
if (customPromptName == "default"){
toastr.error("Cannot save over default prompt")
return
}
Object.assign(extension_settings.objective.customPrompts[customPromptName], objectivePrompts)
saveSettingsDebounced()
populateCustomPrompts()
}
function deleteCustomPrompt(){
const customPromptName = $("#objective-custom-prompt-select").find(':selected').val()
if (customPromptName == "default"){
toastr.error("Cannot delete default prompt")
return
@@ -448,8 +477,7 @@ function deleteCustomPrompt(customPromptName){
}
function loadCustomPrompt(){
const optionSelected = $("#objective-prompt-load").find(':selected').val()
console.log(optionSelected)
const optionSelected = $("#objective-custom-prompt-select").find(':selected').val()
Object.assign(objectivePrompts, extension_settings.objective.customPrompts[optionSelected])
$('#objective-prompt-generate').val(objectivePrompts.createTask)
@@ -459,13 +487,13 @@ function loadCustomPrompt(){
function populateCustomPrompts(){
// Populate saved prompts
$('#objective-prompt-load').empty()
$('#objective-custom-prompt-select').empty()
for (const customPromptName in extension_settings.objective.customPrompts){
const option = document.createElement('option');
option.innerText = customPromptName;
option.value = customPromptName;
option.selected = customPromptName
$('#objective-prompt-load').append(option)
$('#objective-custom-prompt-select').append(option)
}
}
@@ -574,8 +602,10 @@ function onChatDepthInput() {
}
function onObjectiveTextFocusOut(){
currentObjective.description = $('#objective-text').val()
saveState()
if (currentObjective){
currentObjective.description = $('#objective-text').val()
saveState()
}
}
// Update how often we check for task completion
@@ -752,7 +782,7 @@ jQuery(() => {
});
eventSource.on(event_types.MESSAGE_RECEIVED, () => {
if (currentChatId == undefined) {
if (currentChatId == undefined || currentTask == undefined) {
return
}
if ($("#objective-check-frequency").val() > 0) {

View File

@@ -1,19 +1,48 @@
import { saveSettingsDebounced } from "../../../script.js";
import { saveSettingsDebounced, callPopup, getRequestHeaders } from "../../../script.js";
import { getContext, extension_settings } from "../../extensions.js";
import { initScrollHeight, resetScrollHeight } from "../../utils.js";
export { MODULE_NAME };
const MODULE_NAME = 'quick-reply';
const UPDATE_INTERVAL = 1000;
let presets = [];
let selected_preset = '';
const defaultSettings = {
quickReplyEnabled: false,
quickReplyEnabled: true,
numberOfSlots: 5,
quickReplySlots: [],
}
async function loadSettings() {
//method from worldinfo
async function updateQuickReplyPresetList() {
var result = await fetch("/getsettings", {
method: "POST",
headers: getRequestHeaders(),
body: JSON.stringify({}),
});
if (result.ok) {
var data = await result.json();
presets = data.quickReplyPresets?.length ? data.quickReplyPresets : [];
console.log(presets)
$("#quickReplyPresets").find('option[value!=""]').remove();
if (presets !== undefined) {
presets.forEach((item, i) => {
$("#quickReplyPresets").append(`<option value='${item.name}'${selected_preset.includes(item.name) ? ' selected' : ''}>${item.name}</option>`);
});
}
}
}
async function loadSettings(type) {
if (type === 'init') {
await updateQuickReplyPresetList()
}
if (Object.keys(extension_settings.quickReply).length === 0) {
Object.assign(extension_settings.quickReply, defaultSettings);
}
@@ -111,6 +140,51 @@ async function moduleWorker() {
if (extension_settings.quickReply.quickReplyEnabled === true) {
$('#quickReplyBar').toggle(getContext().onlineStatus !== 'no_connection');
}
if (extension_settings.quickReply.selectedPreset) {
selected_preset = extension_settings.quickReply.selectedPreset;
}
}
async function saveQuickReplyPreset() {
const name = await callPopup('Enter a name for the Quick Reply Preset:', 'input');
if (!name) {
return;
}
const quickReplyPreset = {
name: name,
quickReplyEnabled: extension_settings.quickReply.quickReplyEnabled,
quickReplySlots: extension_settings.quickReply.quickReplySlots,
numberOfSlots: extension_settings.quickReply.numberOfSlots,
selectedPreset: name
}
const response = await fetch('/savequickreply', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify(quickReplyPreset)
});
if (response.ok) {
const quickReplyPresetIndex = presets.findIndex(x => x.name == name);
if (quickReplyPresetIndex == -1) {
presets.push(quickReplyPreset);
const option = document.createElement('option');
option.selected = true;
option.value = name;
option.innerText = name;
$('#quickReplyPresets').append(option);
}
else {
presets[quickReplyPresetIndex] = quickReplyPreset;
$(`#quickReplyPresets option[value="${name}"]`).attr('selected', true);
}
saveSettingsDebounced();
} else {
toastr.warning('Failed to save Quick Reply Preset.')
}
}
async function onQuickReplyNumberOfSlotsInput() {
@@ -178,6 +252,27 @@ function generateQuickReplyElements() {
});
}
async function applyQuickReplyPreset(name) {
const quickReplyPreset = presets.find(x => x.name == name);
if (!quickReplyPreset) {
console.log(`error, QR preset '${name}' not found`)
return;
}
extension_settings.quickReply = quickReplyPreset;
extension_settings.quickReply.selectedPreset = name;
saveSettingsDebounced()
loadSettings('init')
addQuickReplyBar();
moduleWorker();
$(`#quickReplyPresets option[value="${name}"]`).attr('selected', true);
console.debug('QR Preset applied: ' + name);
//loadMovingUIState()
}
jQuery(async () => {
moduleWorker();
@@ -190,11 +285,18 @@ jQuery(async () => {
<div class="inline-drawer-icon fa-solid fa-circle-chevron-down down"></div>
</div>
<div class="inline-drawer-content">
<label class="checkbox_label marginBot10">
<input id="quickReplyEnabled" type="checkbox" />
Enable Quick Replies
</label>
<label for="quickReplyNumberOfSlots">Number of slots:</label>
<div class="flex-container ">
<label class="checkbox_label marginBot10 wide100p flexnowrap">
<input id="quickReplyEnabled" type="checkbox" />
Enable Quick Replies
</label>
<div class="flex-container flexnowrap wide100p">
<select id="quickReplyPresets" name="quickreply-preset">
</select>
<i id="quickReplyPresetSaveButton" class="fa-solid fa-save"></i>
</div>
<label for="quickReplyNumberOfSlots">Number of slots:</label>
</div>
<div class="flex-container flexGap5 flexnowrap">
<input id="quickReplyNumberOfSlots" class="text_pole" type="number" min="1" max="100" value="" />
<div class="menu_button menu_button_icon" id="quickReplyNumberOfSlotsApply">
@@ -212,8 +314,17 @@ jQuery(async () => {
$('#quickReplyEnabled').on('input', onQuickReplyEnabledInput);
$('#quickReplyNumberOfSlotsApply').on('click', onQuickReplyNumberOfSlotsInput);
$("#quickReplyPresetSaveButton").on('click', saveQuickReplyPreset);
await loadSettings();
$("#quickReplyPresets").on('change', async function () {
const quickReplyPresetSelected = $(this).find(':selected').val();
extension_settings.quickReplyPreset = quickReplyPresetSelected;
applyQuickReplyPreset(quickReplyPresetSelected);
saveSettingsDebounced();
});
await loadSettings('init');
addQuickReplyBar();
});

View File

@@ -5,6 +5,7 @@ import {
delay,
isDataURL,
createThumbnail,
extractAllWords,
} from './utils.js';
import { RA_CountCharTokens, humanizedDateTime, dragElement } from "./RossAscends-mods.js";
import { sortCharactersList, sortGroupMembers, loadMovingUIState } from './power-user.js';
@@ -782,19 +783,6 @@ function activateNaturalOrder(members, input, lastMessage, allowSelfResponses, i
return memberIds;
}
function extractAllWords(value) {
const words = [];
if (!value) {
return words;
}
const matches = value.matchAll(/\b\w+\b/gim);
for (let match of matches) {
words.push(match[0].toLowerCase());
}
return words;
}
async function deleteGroup(id) {

View File

@@ -102,7 +102,7 @@ const phraseRepPenStrings = [
]
function getPhraseRepPenString(phraseRepPenCounter) {
if (phraseRepPenCounter < 1 || phraseRepPenCounter > F5) {
if (phraseRepPenCounter < 1 || phraseRepPenCounter > 5) {
return null;
} else {
return phraseRepPenStrings[phraseRepPenCounter];

View File

@@ -143,6 +143,7 @@ const default_settings = {
api_url_scale: '',
show_external_models: false,
proxy_password: '',
assistant_prefill: '',
};
const oai_settings = {
@@ -180,6 +181,7 @@ const oai_settings = {
api_url_scale: '',
show_external_models: false,
proxy_password: '',
assistant_prefill: '',
};
let openai_setting_names;
@@ -775,6 +777,7 @@ async function sendOpenAIRequest(type, openai_msgs_tosend, signal) {
if (isClaude) {
generate_data['use_claude'] = true;
generate_data['top_k'] = parseFloat(oai_settings.top_k_openai);
generate_data['assistant_prefill'] = substituteParams(oai_settings.assistant_prefill);
}
if (isOpenRouter) {
@@ -1109,6 +1112,7 @@ function loadOpenAISettings(data, settings) {
oai_settings.api_url_scale = settings.api_url_scale ?? default_settings.api_url_scale;
oai_settings.show_external_models = settings.show_external_models ?? default_settings.show_external_models;
oai_settings.proxy_password = settings.proxy_password ?? default_settings.proxy_password;
oai_settings.assistant_prefill = settings.assistant_prefill ?? default_settings.assistant_prefill;
if (settings.nsfw_toggle !== undefined) oai_settings.nsfw_toggle = !!settings.nsfw_toggle;
if (settings.keep_example_dialogue !== undefined) oai_settings.keep_example_dialogue = !!settings.keep_example_dialogue;
@@ -1121,6 +1125,7 @@ function loadOpenAISettings(data, settings) {
$('#stream_toggle').prop('checked', oai_settings.stream_openai);
$('#api_url_scale').val(oai_settings.api_url_scale);
$('#openai_proxy_password').val(oai_settings.proxy_password);
$('#claude_assistant_prefill').val(oai_settings.assistant_prefill);
$('#model_openai_select').val(oai_settings.openai_model);
$(`#model_openai_select option[value="${oai_settings.openai_model}"`).attr('selected', true);
@@ -1323,6 +1328,7 @@ async function saveOpenAIPreset(name, settings) {
stream_openai: settings.stream_openai,
api_url_scale: settings.api_url_scale,
show_external_models: settings.show_external_models,
assistant_prefill: settings.assistant_prefill,
};
const savePresetSettings = await fetch(`/savepreset_openai?name=${name}`, {
@@ -1656,6 +1662,7 @@ function onSettingsPresetChange() {
api_url_scale: ['#api_url_scale', 'api_url_scale', false],
show_external_models: ['#openai_show_external_models', 'show_external_models', true],
proxy_password: ['#openai_proxy_password', 'proxy_password', false],
assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false],
};
for (const [key, [selector, setting, isCheckbox]] of Object.entries(settingsToUpdate)) {
@@ -2206,6 +2213,11 @@ $(document).ready(function () {
saveSettingsDebounced();
});
$('#claude_assistant_prefill').on('input', function () {
oai_settings.assistant_prefill = $(this).val();
saveSettingsDebounced();
});
$("#api_button_openai").on("click", onConnectButtonClick);
$("#openai_reverse_proxy").on("input", onReverseProxyInput);
$("#model_openai_select").on("change", onModelChange);

View File

@@ -1224,12 +1224,6 @@ async function doMesCut(_, text) {
return
}
//reject attempts to delete firstmes
if (text === '0') {
toastr.error('Cannot delete the First Message')
return
}
let mesIDToCut = Number(text).toFixed(0)
let mesToCut = $("#chat").find(`.mes[mesid=${mesIDToCut}]`)

View File

@@ -470,6 +470,20 @@ export function getCharaFilename(chid) {
}
}
export function extractAllWords(value) {
const words = [];
if (!value) {
return words;
}
const matches = value.matchAll(/\b\w+\b/gim);
for (let match of matches) {
words.push(match[0].toLowerCase());
}
return words;
}
export function escapeRegex(string) {
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
}

View File

@@ -10,6 +10,7 @@ export {
world_info_budget,
world_info_depth,
world_info_recursive,
world_info_overflow_alert,
world_info_case_sensitive,
world_info_match_whole_words,
world_info_character_strategy,
@@ -32,6 +33,7 @@ let world_names;
let world_info_depth = 2;
let world_info_budget = 25;
let world_info_recursive = false;
let world_info_overflow_alert = false;
let world_info_case_sensitive = false;
let world_info_match_whole_words = false;
let world_info_character_strategy = world_info_insertion_strategy.character_first;
@@ -70,6 +72,8 @@ function setWorldInfoSettings(settings, data) {
world_info_budget = Number(settings.world_info_budget);
if (settings.world_info_recursive !== undefined)
world_info_recursive = Boolean(settings.world_info_recursive);
if (settings.world_info_overflow_alert !== undefined)
world_info_overflow_alert = Boolean(settings.world_info_overflow_alert);
if (settings.world_info_case_sensitive !== undefined)
world_info_case_sensitive = Boolean(settings.world_info_case_sensitive);
if (settings.world_info_match_whole_words !== undefined)
@@ -102,6 +106,7 @@ function setWorldInfoSettings(settings, data) {
$("#world_info_budget").val(world_info_budget);
$("#world_info_recursive").prop('checked', world_info_recursive);
$("#world_info_overflow_alert").prop('checked', world_info_overflow_alert);
$("#world_info_case_sensitive").prop('checked', world_info_case_sensitive);
$("#world_info_match_whole_words").prop('checked', world_info_match_whole_words);
@@ -1020,6 +1025,10 @@ async function checkWorldInfo(chat, maxContext) {
if (textToScanTokens + getTokenCount(newContent) >= budget) {
console.debug(`WI budget reached, stopping`);
if (world_info_overflow_alert) {
console.log("Alerting");
toastr.warning(`World info budget reached after ${count} entries.`, 'World Info');
}
needsToScan = false;
break;
}
@@ -1501,6 +1510,11 @@ jQuery(() => {
saveSettingsDebounced();
});
$('#world_info_overflow_alert').on('change', function () {
world_info_overflow_alert = $(this).val();
saveSettingsDebounced();
});
$('#world_button').on('click', async function () {
const chid = $('#set_character_world').data('chid');

View File

@@ -609,7 +609,7 @@ hr {
display: flex;
column-gap: 10px;
cursor: pointer;
align-items: baseline;
}
#extensionsMenu>div,
@@ -1293,7 +1293,7 @@ body.charListGrid #rm_print_characters_block .tags_inline {
}
.floating_prompt_radio_group {
.floating_prompt_radio_group, .radio_group {
display: flex;
flex-direction: column;
}

View File

@@ -290,6 +290,7 @@ const directories = {
instruct: 'public/instruct',
context: 'public/context',
backups: 'backups/',
quickreplies: 'public/QuickReplies'
};
// CSRF Protection //
@@ -1600,6 +1601,8 @@ app.post('/getsettings', jsonParser, (request, response) => {
const themes = readAndParseFromDirectory(directories.themes);
const movingUIPresets = readAndParseFromDirectory(directories.movingUI);
const quickReplyPresets = readAndParseFromDirectory(directories.quickreplies);
const instruct = readAndParseFromDirectory(directories.instruct);
const context = readAndParseFromDirectory(directories.context);
@@ -1616,6 +1619,7 @@ app.post('/getsettings', jsonParser, (request, response) => {
textgenerationwebui_preset_names,
themes,
movingUIPresets,
quickReplyPresets,
instruct,
context,
enable_extensions: enableExtensions,
@@ -1672,6 +1676,17 @@ app.post('/savemovingui', jsonParser, (request, response) => {
return response.sendStatus(200);
});
app.post('/savequickreply', jsonParser, (request, response) => {
if (!request.body || !request.body.name) {
return response.sendStatus(400);
}
const filename = path.join(directories.quickreplies, sanitize(request.body.name) + '.json');
fs.writeFileSync(filename, JSON.stringify(request.body, null, 4), 'utf8');
return response.sendStatus(200);
});
function convertWorldInfoToCharacterBook(name, entries) {
const result = { entries: [], name };
@@ -1783,10 +1798,10 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
request.socket.on('close', function () {
controller.abort();
});
console.log(request.body);
const bw = require('./src/bad-words');
const novelai = require('./src/novelai');
const isNewModel = (request.body.model.includes('clio') || request.body.model.includes('kayra'));
const isKrake = request.body.model.includes('krake');
const data = {
"input": request.body.input,
"model": request.body.model,
@@ -1801,6 +1816,7 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
"repetition_penalty_slope": request.body.repetition_penalty_slope,
"repetition_penalty_frequency": request.body.repetition_penalty_frequency,
"repetition_penalty_presence": request.body.repetition_penalty_presence,
"repetition_penalty_whitelist": isNewModel ? novelai.repPenaltyAllowList : null,
"top_a": request.body.top_a,
"top_p": request.body.top_p,
"top_k": request.body.top_k,
@@ -1809,15 +1825,18 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
"cfg_uc": request.body.cfg_uc,
"phrase_rep_pen": request.body.phrase_rep_pen,
//"stop_sequences": {{187}},
"bad_words_ids": isNewModel ? bw.clioBadWordsId : bw.badWordIds,
"bad_words_ids": isNewModel ? novelai.badWordsList : (isKrake ? novelai.krakeBadWordsList : novelai.euterpeBadWordsList),
"logit_bias_exp": isNewModel ? novelai.logitBiasExp : null,
//generate_until_sentence = true;
"use_cache": request.body.use_cache,
"use_string": true,
"return_full_text": request.body.return_full_text,
"prefix": isNewModel ? "special_instruct" : request.body.prefix,
"prefix": request.body.prefix,
"order": request.body.order
}
};
const util = require('util');
console.log(util.inspect(data, { depth: 4 }))
const args = {
body: JSON.stringify(data),
@@ -3077,7 +3096,12 @@ async function sendClaudeRequest(request, response) {
controller.abort();
});
const requestPrompt = convertClaudePrompt(request.body.messages, true, true);
let requestPrompt = convertClaudePrompt(request.body.messages, true, true);
if (request.body.assistant_prefill) {
requestPrompt += request.body.assistant_prefill;
}
console.log('Claude request:', requestPrompt);
const generateResponse = await fetch(api_url + '/complete', {

View File

@@ -1,326 +0,0 @@
const badWordIds = [
[60],
[62],
[544],
[683],
[696],
[880],
[905],
[1008],
[1019],
[1084],
[1092],
[1181],
[1184],
[1254],
[1447],
[1570],
[1656],
[2194],
[2470],
[2479],
[2498],
[2947],
[3138],
[3291],
[3455],
[3725],
[3851],
[3891],
[3921],
[3951],
[4207],
[4299],
[4622],
[4681],
[5013],
[5032],
[5180],
[5218],
[5290],
[5413],
[5456],
[5709],
[5749],
[5774],
[6038],
[6257],
[6334],
[6660],
[6904],
[7082],
[7086],
[7254],
[7444],
[7748],
[8001],
[8088],
[8168],
[8562],
[8605],
[8795],
[8850],
[9014],
[9102],
[9259],
[9318],
[9336],
[9502],
[9686],
[9793],
[9855],
[9899],
[9955],
[10148],
[10174],
[10943],
[11326],
[11337],
[11661],
[12004],
[12084],
[12159],
[12520],
[12977],
[13380],
[13488],
[13663],
[13811],
[13976],
[14412],
[14598],
[14767],
[15640],
[15707],
[15775],
[15830],
[16079],
[16354],
[16369],
[16445],
[16595],
[16614],
[16731],
[16943],
[17278],
[17281],
[17548],
[17555],
[17981],
[18022],
[18095],
[18297],
[18413],
[18736],
[18772],
[18990],
[19181],
[20095],
[20197],
[20481],
[20629],
[20871],
[20879],
[20924],
[20977],
[21375],
[21382],
[21391],
[21687],
[21810],
[21828],
[21938],
[22367],
[22372],
[22734],
[23405],
[23505],
[23734],
[23741],
[23781],
[24237],
[24254],
[24345],
[24430],
[25416],
[25896],
[26119],
[26635],
[26842],
[26991],
[26997],
[27075],
[27114],
[27468],
[27501],
[27618],
[27655],
[27720],
[27829],
[28052],
[28118],
[28231],
[28532],
[28571],
[28591],
[28653],
[29013],
[29547],
[29650],
[29925],
[30522],
[30537],
[30996],
[31011],
[31053],
[31096],
[31148],
[31258],
[31350],
[31379],
[31422],
[31789],
[31830],
[32214],
[32666],
[32871],
[33094],
[33376],
[33440],
[33805],
[34368],
[34398],
[34417],
[34418],
[34419],
[34476],
[34494],
[34607],
[34758],
[34761],
[34904],
[34993],
[35117],
[35138],
[35237],
[35487],
[35830],
[35869],
[36033],
[36134],
[36320],
[36399],
[36487],
[36586],
[36676],
[36692],
[36786],
[37077],
[37594],
[37596],
[37786],
[37982],
[38475],
[38791],
[39083],
[39258],
[39487],
[39822],
[40116],
[40125],
[41000],
[41018],
[41256],
[41305],
[41361],
[41447],
[41449],
[41512],
[41604],
[42041],
[42274],
[42368],
[42696],
[42767],
[42804],
[42854],
[42944],
[42989],
[43134],
[43144],
[43189],
[43521],
[43782],
[44082],
[44162],
[44270],
[44308],
[44479],
[44524],
[44965],
[45114],
[45301],
[45382],
[45443],
[45472],
[45488],
[45507],
[45564],
[45662],
[46265],
[46267],
[46275],
[46295],
[46462],
[46468],
[46576],
[46694],
[47093],
[47384],
[47389],
[47446],
[47552],
[47686],
[47744],
[47916],
[48064],
[48167],
[48392],
[48471],
[48664],
[48701],
[49021],
[49193],
[49236],
[49550],
[49694],
[49806],
[49824],
[50001],
[50256],
[0],
[1],
]
const clioBadWordsId = [
[3],
[49356],
[1431],
[31715],
[34387],
[20765],
[30702],
[10691],
[49333],
[1266],
[19438],
[43145],
[26523],
[41471],
[2936],
]
module.exports = {
badWordIds,
clioBadWordsId,
};

75
src/novelai.js Normal file
View File

@@ -0,0 +1,75 @@
// Ban bracket generation, plus defaults
const euterpeBadWordsList = [
[8162], [17202], [8162], [17202], [8162], [17202], [8162], [17202], [8162], [17202], [46256, 224], [2343, 223, 224],
[46256, 224], [2343, 223, 224], [46256, 224], [2343, 223, 224], [46256, 224], [2343, 223, 224], [46256, 224],
[2343, 223, 224], [58], [60], [90], [92], [685], [1391], [1782], [2361], [3693], [4083], [4357], [4895], [5512],
[5974], [7131], [8183], [8351], [8762], [8964], [8973], [9063], [11208], [11709], [11907], [11919], [12878], [12962],
[13018], [13412], [14631], [14692], [14980], [15090], [15437], [16151], [16410], [16589], [17241], [17414], [17635],
[17816], [17912], [18083], [18161], [18477], [19629], [19779], [19953], [20520], [20598], [20662], [20740], [21476],
[21737], [22133], [22241], [22345], [22935], [23330], [23785], [23834], [23884], [25295], [25597], [25719], [25787],
[25915], [26076], [26358], [26398], [26894], [26933], [27007], [27422], [28013], [29164], [29225], [29342], [29565],
[29795], [30072], [30109], [30138], [30866], [31161], [31478], [32092], [32239], [32509], [33116], [33250], [33761],
[34171], [34758], [34949], [35944], [36338], [36463], [36563], [36786], [36796], [36937], [37250], [37913], [37981],
[38165], [38362], [38381], [38430], [38892], [39850], [39893], [41832], [41888], [42535], [42669], [42785], [42924],
[43839], [44438], [44587], [44926], [45144], [45297], [46110], [46570], [46581], [46956], [47175], [47182], [47527],
[47715], [48600], [48683], [48688], [48874], [48999], [49074], [49082], [49146], [49946], [10221], [4841], [1427],
[2602, 834], [29343], [37405], [35780], [2602], [50256],
]
// Ban bracket generation, plus defaults
const krakeBadWordsList = [
[9264], [14244], [9264], [14244], [9264], [14244], [9264], [14244], [9264], [14244], [25086, 213], [27344, 213],
[25086, 213], [27344, 213], [25086, 213], [27344, 213], [25086, 213], [27344, 213], [25086, 213], [27344, 213], [60],
[62], [544], [683], [696], [880], [905], [1008], [1019], [1084], [1092], [1181], [1184], [1254], [1447], [1570], [1656],
[2194], [2470], [2479], [2498], [2947], [3138], [3291], [3455], [3725], [3851], [3891], [3921], [3951], [4207], [4299],
[4622], [4681], [5013], [5032], [5180], [5218], [5290], [5413], [5456], [5709], [5749], [5774], [6038], [6257], [6334],
[6660], [6904], [7082], [7086], [7254], [7444], [7748], [8001], [8088], [8168], [8562], [8605], [8795], [8850], [9014],
[9102], [9259], [9318], [9336], [9502], [9686], [9793], [9855], [9899], [9955], [10148], [10174], [10943], [11326],
[11337], [11661], [12004], [12084], [12159], [12520], [12977], [13380], [13488], [13663], [13811], [13976], [14412],
[14598], [14767], [15640], [15707], [15775], [15830], [16079], [16354], [16369], [16445], [16595], [16614], [16731],
[16943], [17278], [17281], [17548], [17555], [17981], [18022], [18095], [18297], [18413], [18736], [18772], [18990],
[19181], [20095], [20197], [20481], [20629], [20871], [20879], [20924], [20977], [21375], [21382], [21391], [21687],
[21810], [21828], [21938], [22367], [22372], [22734], [23405], [23505], [23734], [23741], [23781], [24237], [24254],
[24345], [24430], [25416], [25896], [26119], [26635], [26842], [26991], [26997], [27075], [27114], [27468], [27501],
[27618], [27655], [27720], [27829], [28052], [28118], [28231], [28532], [28571], [28591], [28653], [29013], [29547],
[29650], [29925], [30522], [30537], [30996], [31011], [31053], [31096], [31148], [31258], [31350], [31379], [31422],
[31789], [31830], [32214], [32666], [32871], [33094], [33376], [33440], [33805], [34368], [34398], [34417], [34418],
[34419], [34476], [34494], [34607], [34758], [34761], [34904], [34993], [35117], [35138], [35237], [35487], [35830],
[35869], [36033], [36134], [36320], [36399], [36487], [36586], [36676], [36692], [36786], [37077], [37594], [37596],
[37786], [37982], [38475], [38791], [39083], [39258], [39487], [39822], [40116], [40125], [41000], [41018], [41256],
[41305], [41361], [41447], [41449], [41512], [41604], [42041], [42274], [42368], [42696], [42767], [42804], [42854],
[42944], [42989], [43134], [43144], [43189], [43521], [43782], [44082], [44162], [44270], [44308], [44479], [44524],
[44965], [45114], [45301], [45382], [45443], [45472], [45488], [45507], [45564], [45662], [46265], [46267], [46275],
[46295], [46462], [46468], [46576], [46694], [47093], [47384], [47389], [47446], [47552], [47686], [47744], [47916],
[48064], [48167], [48392], [48471], [48664], [48701], [49021], [49193], [49236], [49550], [49694], [49806], [49824],
[50001], [50256], [0], [1]
]
// Ban bracket generation, plus defaults
const badWordsList = [
[23], [49209, 23], [23], [49209, 23], [23], [49209, 23], [23], [49209, 23], [23], [49209, 23], [21], [49209, 21],
[21], [49209, 21], [21], [49209, 21], [21], [49209, 21], [21], [49209, 21], [3], [49356], [1431], [31715], [34387],
[20765], [30702], [10691], [49333], [1266], [26523], [41471], [2936], [85, 85], [49332], [7286], [1115]
]
// Used for phrase repetition penalty
const repPenaltyAllowList = [
[49256, 49264, 49231, 49230, 49287, 85, 49255, 49399, 49262, 336, 333, 432, 363, 468, 492, 745, 401, 426, 623, 794,
1096, 2919, 2072, 7379, 1259, 2110, 620, 526, 487, 16562, 603, 805, 761, 2681, 942, 8917, 653, 3513, 506, 5301,
562, 5010, 614, 10942, 539, 2976, 462, 5189, 567, 2032, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 588,
803, 1040, 49209, 4, 5, 6, 7, 8, 9, 10, 11, 12]
]
// Ban the dinkus and asterism
const logitBiasExp = [
{ "sequence": [23], "bias": -0.08, "ensure_sequence_finish": false, "generate_once": false },
{ "sequence": [21], "bias": -0.08, "ensure_sequence_finish": false, "generate_once": false }
]
module.exports = {
euterpeBadWordsList,
krakeBadWordsList,
badWordsList,
repPenaltyAllowList,
logitBiasExp
};