Merge pull request #856 from mweldon/preamble

This commit is contained in:
Cohee 2023-08-03 10:24:31 +03:00 committed by GitHub
commit 1b005ef47f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 2 deletions

View File

@ -0,0 +1,19 @@
{
"order": [3, 4, 0],
"temperature": 1.19,
"max_length": 300,
"min_length": 1,
"top_a": 0.116,
"tail_free_sampling": 0.958,
"repetition_penalty": 1.64,
"repetition_penalty_slope": 2.12,
"repetition_penalty_frequency": 0,
"repetition_penalty_presence": 0,
"repetition_penalty_range": 2048,
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "medium",
"cfg_scale": 1.0,
"max_context": 7800
}

View File

@ -0,0 +1,19 @@
{
"order": [5, 0, 4],
"temperature": 1,
"max_length": 300,
"min_length": 1,
"top_a": 0.017,
"typical_p": 0.975,
"repetition_penalty": 3,
"repetition_penalty_slope": 0.09,
"repetition_penalty_frequency": 0,
"repetition_penalty_presence": 0,
"repetition_penalty_range": 7680,
"use_cache": false,
"return_full_text": false,
"prefix": "vanilla",
"phrase_rep_pen": "aggressive",
"cfg_scale": 1.0,
"max_context": 7800
}

View File

@ -807,6 +807,22 @@
</div>
</div>
<div id="novel_api-settings">
<div class="range-block">
<div class="range-block-title openai_restorable">
<span data-i18n="Preamble">Preamble</span>
<div id="nai_preamble_restore" title="Restore default prompt" data-i18n="[title]Restore default prompt"
class="right_menu_button">
<div class="fa-solid fa-clock-rotate-left "></div>
</div>
</div>
<div class="toggle-description justifyLeft" data-i18n="Use style tags to improve the quality of the output">
Use style tags to improve the quality of the output
</div>
<div class="wide100p">
<textarea id="nai_preamble_textarea" class="text_pole textarea_compact" name="nai_preamble" rows="2"
placeholder=""></textarea>
</div>
</div>
<div class="range-block">
<div class="range-block-title" data-i18n="Top P">
Top P

View File

@ -3142,7 +3142,15 @@ function parseTokenCounts(counts, thisPromptBits) {
}
function adjustChatsSeparator(mesSendString) {
if (power_user.custom_chat_separator && power_user.custom_chat_separator.length) {
if (main_api === 'novel') {
let preamble = "\n***\n" + nai_settings.nai_preamble;
if (!preamble.endsWith('\n')) {
preamble += '\n';
}
mesSendString = preamble + mesSendString;
}
else if (power_user.custom_chat_separator && power_user.custom_chat_separator.length) {
mesSendString = power_user.custom_chat_separator + '\n' + mesSendString;
}

View File

@ -13,6 +13,8 @@ export {
getNovelTier,
};
const default_preamble = "[ Style: chat, complex, sensory, visceral ]";
const nai_settings = {
temperature: 0.5,
repetition_penalty: 1,
@ -29,6 +31,7 @@ const nai_settings = {
model_novel: "euterpe-v2",
preset_settings_novel: "Classic-Euterpe",
streaming_novel: false,
nai_preamble: default_preamble,
};
const nai_tiers = {
@ -76,6 +79,7 @@ function loadNovelSettings(settings) {
$(`#model_novel_select option[value=${nai_settings.model_novel}]`).attr("selected", true);
$('#model_novel_select').val(nai_settings.model_novel);
if (settings.nai_preamble !== undefined) nai_settings.nai_preamble = settings.nai_preamble;
nai_settings.preset_settings_novel = settings.preset_settings_novel;
nai_settings.temperature = settings.temperature;
nai_settings.repetition_penalty = settings.repetition_penalty;
@ -157,6 +161,7 @@ function loadNovelSettingsUi(ui_settings) {
$("#phrase_rep_pen_counter_novel").text(getPhraseRepPenCounter(ui_settings.phrase_rep_pen));
$("#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);
$("#streaming_novel").prop('checked', ui_settings.streaming_novel);
}
@ -259,6 +264,13 @@ export function getNovelGenerationData(finalPromt, this_settings, this_amount_ge
.map(t => getTextTokens(tokenizerType, t))
: undefined;
let useInstruct = false;
if (isNewModel) {
// 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 {
"input": finalPromt,
"model": nai_settings.model_novel,
@ -286,7 +298,7 @@ export function getNovelGenerationData(finalPromt, this_settings, this_amount_ge
"use_cache": false,
"use_string": true,
"return_full_text": false,
"prefix": isNewModel ? "special_instruct" : "vanilla",
"prefix": useInstruct ? "special_instruct" : (isNewModel ? "special_proseaugmenter" : "vanilla"),
"order": this_settings.order,
"streaming": nai_settings.streaming_novel,
};
@ -334,6 +346,17 @@ export async function generateNovelWithStreaming(generate_data, signal) {
}
}
$("#nai_preamble_textarea").on('input', function () {
nai_settings.nai_preamble = $('#nai_preamble_textarea').val();
saveSettingsDebounced();
});
$("#nai_preamble_restore").on('click', function () {
nai_settings.nai_preamble = default_preamble;
$('#nai_preamble_textarea').val(nai_settings.nai_preamble);
saveSettingsDebounced();
});
$(document).ready(function () {
sliders.forEach(slider => {
$(document).on("input", slider.sliderId, function () {