Merge branch 'SillyTavern:staging' into staging

This commit is contained in:
Tony Ribeiro 2023-08-13 04:16:00 +02:00 committed by GitHub
commit e81f67504f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 13 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>
@ -1498,7 +1513,7 @@
<select id="main_api">
<option value="kobold"><span data-i18n="KoboldAI">KoboldAI</span></option>
<option value="koboldhorde"><span data-i18n="KoboldAI Horde">KoboldAI Horde</span></option>
<option value="textgenerationwebui"><span data-i18n="Text Gen WebUI (ooba)">Text Gen WebUI (ooba)</span></option>
<option value="textgenerationwebui"><span data-i18n="Text Gen WebUI (ooba/Mancer)">Text Gen WebUI (ooba/Mancer)</span></option>
<option value="novel"><span data-i18n="NovelAI">NovelAI</span></option>
<option value="openai"><span data-i18n="Chat Completion (OpenAI, Claude, Window/OpenRouter, Scale)">Chat Completion (OpenAI, Claude, Window, OpenRouter, Scale)</span></option>
</select>
@ -4078,4 +4093,4 @@
</script>
</body>
</html>
</html>

View File

@ -8994,7 +8994,9 @@ $(document).ready(function () {
$dropzone.removeClass('dragover');
const files = Array.from(event.originalEvent.dataTransfer.files);
await importFromURL(event.originalEvent.dataTransfer.items, files);
if (!files.length) {
await importFromURL(event.originalEvent.dataTransfer.items, files);
}
processDroppedFiles(files);
});

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();
});
});