Selectable NovelAI module

This commit is contained in:
Cohee 2023-08-12 21:26:51 +03:00
parent f434a96ad6
commit dd21091807
2 changed files with 45 additions and 10 deletions

View File

@ -835,6 +835,21 @@
</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>

View File

@ -26,12 +26,14 @@ const nai_settings = {
top_k: 0,
top_p: 1,
top_a: 1,
top_g: 0,
typical_p: 1,
min_length: 0,
model_novel: "euterpe-v2",
preset_settings_novel: "Classic-Euterpe",
streaming_novel: false,
nai_preamble: default_preamble,
prefix: '',
};
const nai_tiers = {
@ -92,6 +94,7 @@ function loadNovelPreset(preset) {
nai_settings.top_g = preset.top_g;
nai_settings.mirostat_lr = preset.mirostat_lr;
nai_settings.mirostat_tau = preset.mirostat_tau;
nai_settings.prefix = preset.prefix;
loadNovelSettingsUi(nai_settings);
}
@ -121,6 +124,7 @@ 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.prefix = settings.prefix;
loadNovelSettingsUi(nai_settings);
}
@ -193,6 +197,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 || "");
$("#streaming_novel").prop('checked', ui_settings.streaming_novel);
}
@ -302,10 +307,9 @@ const sliders = [
},
];
export function getNovelGenerationData(finalPromt, this_settings, this_amount_gen, isImpersonate) {
export function getNovelGenerationData(finalPrompt, this_settings, this_amount_gen, isImpersonate) {
const clio = nai_settings.model_novel.includes('clio');
const kayra = nai_settings.model_novel.includes('kayra');
const isNewModel = clio || kayra;
const tokenizerType = kayra ? tokenizers.NERD2 : (clio ? tokenizers.NERD : tokenizers.NONE);
const stopSequences = (tokenizerType !== tokenizers.NONE)
@ -313,15 +317,10 @@ 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("}");
}
const prefix = nai_settings.prefix || autoSelectPrefix(finalPrompt);
return {
"input": finalPromt,
"input": finalPrompt,
"model": nai_settings.model_novel,
"use_string": true,
"temperature": parseFloat(nai_settings.temperature),
@ -350,12 +349,28 @@ export function getNovelGenerationData(finalPromt, this_settings, this_amount_ge
"use_cache": false,
"use_string": true,
"return_full_text": false,
"prefix": useInstruct ? "special_instruct" : (isNewModel ? "special_proseaugmenter" : "vanilla"),
"prefix": prefix,
"order": this_settings.order,
"streaming": nai_settings.streaming_novel,
};
}
function autoSelectPrefix(finalPromt) {
let useInstruct = false;
const clio = nai_settings.model_novel.includes('clio');
const kayra = nai_settings.model_novel.includes('kayra');
const isNewModel = clio || kayra;
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("}");
}
const prefix = useInstruct ? "special_instruct" : (isNewModel ? "special_proseaugmenter" : "vanilla");
return prefix;
}
export async function generateNovelWithStreaming(generate_data, signal) {
const response = await fetch('/generate_novelai', {
headers: getRequestHeaders(),
@ -431,4 +446,9 @@ $(document).ready(function () {
nai_settings.model_novel = $("#model_novel_select").find(":selected").val();
saveSettingsDebounced();
});
$("#nai_prefix").on('change', function () {
nai_settings.prefix = $("#nai_prefix").find(":selected").val();
saveSettingsDebounced();
});
});