Apply preset manager for NovelAI

This commit is contained in:
Cohee 2023-08-16 21:43:38 +03:00
parent 81ed4d8431
commit 1f2394cada
4 changed files with 41 additions and 14 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ public/css/bg_load.css
public/themes/
public/OpenAI Settings/
public/KoboldAI Settings/
public/NovelAI Settings/
public/TextGen Settings/
public/scripts/extensions/third-party/
public/stats.json

View File

@ -160,9 +160,16 @@
<span class="note-link-span">?</span>
</a>
</h3>
<select id="settings_perset_novel" data-preset-manager-for="novel">
<option value="gui" data-i18n="default">Default</option>
</select>
<div class="preset_buttons">
<select id="settings_perset_novel" data-preset-manager-for="novel">
<option value="gui" data-i18n="default">Default</option>
</select>
<i data-preset-manager-update="novel" class="menu_button fa-solid fa-save" title="Update current preset" data-i18n="[title]Update current preset"></i>
<i data-preset-manager-new="novel" class="menu_button fa-solid fa-plus" title="Create new preset" data-i18n="[title]Create new preset"></i>
<i data-preset-manager-import="novel" class="menu_button fa-solid fa-upload" title="Import preset" data-i18n="[title]Import preset"></i>
<i data-preset-manager-export="novel" class="menu_button fa-solid fa-download" title="Export preset" data-i18n="[title]Export preset"></i>
<i data-preset-manager-delete="novel" class="menu_button fa-solid fa-trash-can" title="Delete the preset" data-i18n="[title]Delete the preset"></i>
</div>
</div>
<div id="openai_api-presets">
<div>

View File

@ -2,11 +2,13 @@ import {
getRequestHeaders,
getStoppingStrings,
getTextTokens,
max_context,
novelai_setting_names,
saveSettingsDebounced
saveSettingsDebounced,
setGenerationParamsFromPreset
} from "../script.js";
import { getCfg } from "./extensions/cfg/util.js";
import { tokenizers } from "./power-user.js";
import { MAX_CONTEXT_DEFAULT, tokenizers } from "./power-user.js";
import { getStringHash } from "./utils.js";
export {
@ -81,16 +83,17 @@ function getNovelTier(tier) {
}
function loadNovelPreset(preset) {
$("#amount_gen").val(preset.max_length);
$("#amount_gen_counter").text(`${preset.max_length}`);
if (((preset.max_context > 2048) && (!$("#max_context_unlocked")[0].checked)) ||
((preset.max_context <= 2048) && ($("#max_context_unlocked")[0].checked))) {
$("#max_context_unlocked").click();
if (preset.genamt === undefined) {
const needsUnlock = preset.max_context > MAX_CONTEXT_DEFAULT;
$("#amount_gen").val(preset.max_length).trigger('input');
$('#max_context_unlocked').prop('checked', needsUnlock).trigger('change');
$("#max_context").val(preset.max_context).trigger('input');
}
else {
setGenerationParamsFromPreset(preset);
}
$("#max_context").val(preset.max_context);
$("#max_context_counter").text(`${preset.max_context}`);
$("#rep_pen_size_novel").attr('max', preset.max_context);
$("#rep_pen_size_novel").attr('max', max_context);
nai_settings.temperature = preset.temperature;
nai_settings.repetition_penalty = preset.repetition_penalty;
nai_settings.repetition_penalty_range = preset.repetition_penalty_range;

View File

@ -116,6 +116,12 @@ class PresetManager {
<h3>Preset name:</h3>
<h4>Hint: Use a character/group name to bind preset to a specific chat.</h4>`;
const name = await callPopup(popupText, "input");
if (!name) {
console.log('Preset name not provided');
return;
}
await this.savePreset(name);
toastr.success('Preset saved');
}
@ -214,7 +220,17 @@ class PresetManager {
}
}
const filteredKeys = ['preset', 'streaming_url', 'stopping_strings', 'use_stop_sequence'];
const filteredKeys = [
'preset',
'streaming_url',
'stopping_strings',
'use_stop_sequence',
'preset_settings_novel',
'streaming_novel',
'nai_preamble',
'model_novel',
'preamble',
];
const settings = Object.assign({}, getSettingsByApiId(this.apiId));
for (const key of filteredKeys) {