mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-18 20:22:49 +01:00
Many NovelAI fixes from dev guidance
* Remove AI Module "Autoselect" and make the auto-instruct work for all modules. This is how NAI is supposed to work. * Log the response from the API. * Move the AI Module setting up to the top of the settings window since it isn't part of the preset. * Refactor phrase_rep_pen to use the actual API strings. * Clamp the maximum token length to 150 before we call the API. * Clamp the minimum token length in the UX from 1 to 150. * Fix bug where the preamble was not initialized on cold start. * Get rid of extra newline before dinkus. * Make always_force_name2 default true.
This commit is contained in:
parent
9f49a2612c
commit
41ec7e5600
@ -71,7 +71,7 @@
|
||||
"disable_start_formatting": false,
|
||||
"trim_sentences": false,
|
||||
"include_newline": false,
|
||||
"always_force_name2": false,
|
||||
"always_force_name2": true,
|
||||
"user_prompt_bias": "",
|
||||
"show_user_prompt_bias": true,
|
||||
"multigen": false,
|
||||
|
@ -195,6 +195,24 @@
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<div id="ai_module_block_novel" class="width100p">
|
||||
<div class="range-block">
|
||||
<div class="range-block-title justifyLeft">
|
||||
AI Module
|
||||
</div>
|
||||
<div class="toggle-description justifyLeft"
|
||||
data-i18n="Changes the style of the generated text.">
|
||||
Changes the style of the generated text.
|
||||
</div>
|
||||
<select id="nai_prefix">
|
||||
<option value="vanilla" data-i18n="No Module">No Module</option>
|
||||
<option value="special_instruct" data-i18n="Instruct">Instruct</option>
|
||||
<option value="special_proseaugmenter" data-i18n="Prose Augmenter">Prose Augmenter</option>
|
||||
<option value="theme_textadventure" data-i18n="Text Adventure">Text Adventure</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="common-gen-settings-block" class="width100p">
|
||||
<div id="pro-settings-block">
|
||||
<div id="amount_gen_block" class="range-block">
|
||||
@ -432,12 +450,12 @@
|
||||
Phrase Repetition Penalty
|
||||
</div>
|
||||
<select id="phrase_rep_pen_novel">
|
||||
<option value="0" data-i18n="Disabled">Disabled</option>
|
||||
<option value="1" data-i18n="Very Light">Very Light</option>
|
||||
<option value="2" data-i18n="Light">Light</option>
|
||||
<option value="3" data-i18n="Medium">Medium</option>
|
||||
<option value="4" data-i18n="Aggressive">Aggressive</option>
|
||||
<option value="5" data-i18n="Very Aggressive">Very Aggressive</option>
|
||||
<option value="off" data-i18n="Off">Disabled</option>
|
||||
<option value="very_light" data-i18n="Very Light">Very Light</option>
|
||||
<option value="light" data-i18n="Light">Light</option>
|
||||
<option value="medium" data-i18n="Medium">Medium</option>
|
||||
<option value="aggressive" data-i18n="Aggressive">Aggressive</option>
|
||||
<option value="very_aggressive" data-i18n="Very Aggressive">Very Aggressive</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@ -850,21 +868,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="novel_api-settings">
|
||||
<div class="range-block">
|
||||
<div class="range-block-title justifyLeft">
|
||||
AI Module
|
||||
</div>
|
||||
<div class="toggle-description justifyLeft" data-i18n="Change the style of the generated text. Set to Vanilla to use the default style.">
|
||||
Change the style of the generated text. Set to Vanilla to use the default style.
|
||||
</div>
|
||||
<select id="nai_prefix">
|
||||
<option value="" data-i18n="Auto-select">Auto-select</option>
|
||||
<option value="vanilla" data-i18n="Vanilla">Vanilla</option>
|
||||
<option value="special_instruct" data-i18n="Instruct">Instruct</option>
|
||||
<option value="special_proseaugmenter" data-i18n="Prose Augmenter">Prose Augmenter</option>
|
||||
<option value="theme_textadventure" data-i18n="Text Adventure">Text Adventure</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="range-block">
|
||||
<div class="range-block-title openai_restorable">
|
||||
<span data-i18n="Preamble">Preamble</span>
|
||||
@ -1018,7 +1021,7 @@
|
||||
</div>
|
||||
<div class="range-block-range-and-counter">
|
||||
<div class="range-block-range">
|
||||
<input type="range" id="min_length_novel" name="volume" min="0" max="1024" step="1">
|
||||
<input type="range" id="min_length_novel" name="volume" min="1" max="150" step="1">
|
||||
</div>
|
||||
<div class="range-block-counter">
|
||||
<div contenteditable="true" data-for="min_length_novel" id="min_length_counter_novel">
|
||||
|
@ -3334,8 +3334,9 @@ function parseTokenCounts(counts, thisPromptBits) {
|
||||
}
|
||||
|
||||
function addChatsPreamble(mesSendString) {
|
||||
const preamble = main_api === 'novel' ? nai_settings.preamble : "";
|
||||
return preamble + '\n' + mesSendString;
|
||||
return main_api === 'novel'
|
||||
? nai_settings.preamble + '\n' + mesSendString
|
||||
: mesSendString;
|
||||
}
|
||||
|
||||
function addChatsSeparator(mesSendString) {
|
||||
@ -3349,7 +3350,7 @@ function addChatsSeparator(mesSendString) {
|
||||
}
|
||||
|
||||
else if (main_api === 'novel') {
|
||||
mesSendString = '\n***\n' + mesSendString;
|
||||
mesSendString = '***\n' + mesSendString;
|
||||
}
|
||||
|
||||
// add non-pygma dingus
|
||||
@ -4609,6 +4610,12 @@ function changeMainAPI() {
|
||||
activeItem.amountGenElem.css("opacity", 1.0);
|
||||
}
|
||||
|
||||
if (selectedVal === "novel") {
|
||||
$("#ai_module_block_novel").css("display", "block");
|
||||
} else {
|
||||
$("#ai_module_block_novel").css("display", "none");
|
||||
}
|
||||
|
||||
// Hide common settings for OpenAI
|
||||
console.debug('value?', selectedVal);
|
||||
if (selectedVal == "openai") {
|
||||
|
@ -15,6 +15,7 @@ export {
|
||||
};
|
||||
|
||||
const default_preamble = "[ Style: chat, complex, sensory, visceral ]";
|
||||
const maximum_output_length = 150;
|
||||
|
||||
const nai_settings = {
|
||||
temperature: 0.5,
|
||||
@ -127,44 +128,12 @@ function loadNovelSettings(settings) {
|
||||
nai_settings.mirostat_lr = settings.mirostat_lr;
|
||||
nai_settings.mirostat_tau = settings.mirostat_tau;
|
||||
nai_settings.streaming_novel = !!settings.streaming_novel;
|
||||
nai_settings.preamble = settings.preamble || default_preamble;
|
||||
nai_settings.prefix = settings.prefix;
|
||||
nai_settings.cfg_uc = settings.cfg_uc || '';
|
||||
loadNovelSettingsUi(nai_settings);
|
||||
}
|
||||
|
||||
const phraseRepPenStrings = [
|
||||
null,
|
||||
"very_light",
|
||||
"light",
|
||||
"medium",
|
||||
"aggressive",
|
||||
"very_aggressive"
|
||||
]
|
||||
|
||||
function getPhraseRepPenString(phraseRepPenCounter) {
|
||||
if (phraseRepPenCounter < 1 || phraseRepPenCounter > 5) {
|
||||
return null;
|
||||
} else {
|
||||
return phraseRepPenStrings[phraseRepPenCounter];
|
||||
}
|
||||
}
|
||||
|
||||
function getPhraseRepPenCounter(phraseRepPenString) {
|
||||
if (phraseRepPenString === phraseRepPenStrings[1]) {
|
||||
return 1;
|
||||
} else if (phraseRepPenString === phraseRepPenStrings[2]) {
|
||||
return 2;
|
||||
} else if (phraseRepPenString === phraseRepPenStrings[3]) {
|
||||
return 3;
|
||||
} else if (phraseRepPenString === phraseRepPenStrings[4]) {
|
||||
return 4;
|
||||
} else if (phraseRepPenString === phraseRepPenStrings[5]) {
|
||||
return 5;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function loadNovelSettingsUi(ui_settings) {
|
||||
$("#temp_novel").val(ui_settings.temperature);
|
||||
$("#temp_counter_novel").text(Number(ui_settings.temperature).toFixed(2));
|
||||
@ -190,7 +159,7 @@ function loadNovelSettingsUi(ui_settings) {
|
||||
$("#typical_p_counter_novel").text(Number(ui_settings.typical_p).toFixed(2));
|
||||
$("#cfg_scale_novel").val(ui_settings.cfg_scale);
|
||||
$("#cfg_scale_counter_novel").text(Number(ui_settings.cfg_scale).toFixed(2));
|
||||
$("#phrase_rep_pen_novel").val(getPhraseRepPenCounter(ui_settings.phrase_rep_pen));
|
||||
$("#phrase_rep_pen_novel").val(ui_settings.phrase_rep_pen || "off");
|
||||
$("#top_g_novel").val(ui_settings.top_g);
|
||||
$("#top_g_counter_novel").text(Number(ui_settings.top_g).toFixed(0));
|
||||
$("#mirostat_lr_novel").val(ui_settings.mirostat_lr);
|
||||
@ -200,7 +169,7 @@ function loadNovelSettingsUi(ui_settings) {
|
||||
$("#min_length_novel").val(ui_settings.min_length);
|
||||
$("#min_length_counter_novel").text(Number(ui_settings.min_length).toFixed(0));
|
||||
$('#nai_preamble_textarea').val(ui_settings.nai_preamble);
|
||||
$('#nai_prefix').val(ui_settings.prefix || "");
|
||||
$('#nai_prefix').val(ui_settings.prefix || "vanilla");
|
||||
$('#nai_cfg_uc').val(ui_settings.cfg_uc || "");
|
||||
|
||||
$("#streaming_novel").prop('checked', ui_settings.streaming_novel);
|
||||
@ -321,7 +290,7 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
|
||||
.map(t => getTextTokens(tokenizerType, t))
|
||||
: undefined;
|
||||
|
||||
const prefix = nai_settings.prefix || autoSelectPrefix(finalPrompt);
|
||||
const prefix = selectPrefix(nai_settings.prefix, finalPrompt);
|
||||
const cfgSettings = getCfg();
|
||||
|
||||
return {
|
||||
@ -329,7 +298,7 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
|
||||
"model": nai_settings.model_novel,
|
||||
"use_string": true,
|
||||
"temperature": parseFloat(nai_settings.temperature),
|
||||
"max_length": this_amount_gen, // this_settings.max_length, // <= why?
|
||||
"max_length": this_amount_gen < maximum_output_length ? this_amount_gen : maximum_output_length,
|
||||
"min_length": parseInt(nai_settings.min_length),
|
||||
"tail_free_sampling": parseFloat(nai_settings.tail_free_sampling),
|
||||
"repetition_penalty": parseFloat(nai_settings.repetition_penalty),
|
||||
@ -347,8 +316,8 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
|
||||
"cfg_scale": cfgSettings?.guidanceScale ?? parseFloat(nai_settings.cfg_scale),
|
||||
"cfg_uc": cfgSettings?.negativePrompt ?? nai_settings.cfg_uc ?? "",
|
||||
"phrase_rep_pen": nai_settings.phrase_rep_pen,
|
||||
//"stop_sequences": {{187}},
|
||||
"stop_sequences": stopSequences,
|
||||
// These get added by the server
|
||||
//bad_words_ids = {{50256}, {0}, {1}};
|
||||
"generate_until_sentence": true,
|
||||
"use_cache": false,
|
||||
@ -360,7 +329,8 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
|
||||
};
|
||||
}
|
||||
|
||||
function autoSelectPrefix(finalPromt) {
|
||||
// Check if the prefix needs to be overriden to use instruct mode
|
||||
function selectPrefix(selected_prefix, finalPromt) {
|
||||
let useInstruct = false;
|
||||
const clio = nai_settings.model_novel.includes('clio');
|
||||
const kayra = nai_settings.model_novel.includes('kayra');
|
||||
@ -370,10 +340,10 @@ function autoSelectPrefix(finalPromt) {
|
||||
// NovelAI claims they scan backwards 1000 characters (not tokens!) to look for instruct brackets. That's really short.
|
||||
const tail = finalPromt.slice(-1500);
|
||||
useInstruct = tail.includes("}");
|
||||
return useInstruct ? "special_instruct" : selected_prefix;
|
||||
}
|
||||
|
||||
const prefix = useInstruct ? "special_instruct" : (isNewModel ? "special_proseaugmenter" : "vanilla");
|
||||
return prefix;
|
||||
return "vanilla";
|
||||
}
|
||||
|
||||
export async function generateNovelWithStreaming(generate_data, signal) {
|
||||
@ -458,8 +428,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$("#phrase_rep_pen_novel").on('change', function () {
|
||||
const val = $("#phrase_rep_pen_novel").find(":selected").val();
|
||||
nai_settings.phrase_rep_pen = getPhraseRepPenString(Number(val).toFixed(0));
|
||||
nai_settings.phrase_rep_pen = $("#phrase_rep_pen_novel").find(":selected").val();
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user