Apply preset manager for instruct presets

This commit is contained in:
Cohee
2023-08-21 00:56:53 +03:00
parent 8bb59a9e22
commit 897ad28477
17 changed files with 146 additions and 99 deletions

View File

@@ -16,13 +16,15 @@ import {
this_chid,
} from "../script.js";
import { groups, selected_group } from "./group-chats.js";
import { instruct_presets } from "./instruct-mode.js";
import { kai_settings } from "./kai-settings.js";
import { power_user } from "./power-user.js";
import {
textgenerationwebui_preset_names,
textgenerationwebui_presets,
textgenerationwebui_settings,
} from "./textgen-settings.js";
import { download, parseJsonFile, waitUntilCondition } from "./utils.js";
import { deepClone, download, parseJsonFile, waitUntilCondition } from "./utils.js";
const presetManagers = {};
@@ -164,6 +166,10 @@ class PresetManager {
presets = textgenerationwebui_presets;
preset_names = textgenerationwebui_preset_names;
break;
case "instruct":
presets = instruct_presets;
preset_names = instruct_presets.map(x => x.name);
break;
default:
console.warn(`Unknown API ID ${this.apiId}`);
}
@@ -171,12 +177,20 @@ class PresetManager {
return { presets, preset_names };
}
isKeyedApi() {
return this.apiId == "textgenerationwebui" || this.apiId == "instruct";
}
isNonGenericApi() {
return this.apiId == "instruct";
}
updateList(name, preset) {
const { presets, preset_names } = this.getPresetList();
const presetExists = this.apiId == "textgenerationwebui" ? preset_names.includes(name) : Object.keys(preset_names).includes(name);
const presetExists = this.isKeyedApi() ? preset_names.includes(name) : Object.keys(preset_names).includes(name);
if (presetExists) {
if (this.apiId == "textgenerationwebui") {
if (this.isKeyedApi()) {
presets[preset_names.indexOf(name)] = preset;
$(this.select).find(`option[value="${name}"]`).prop('selected', true);
$(this.select).val(name).trigger("change");
@@ -191,8 +205,8 @@ class PresetManager {
else {
presets.push(preset);
const value = presets.length - 1;
// ooba is reversed
if (this.apiId == "textgenerationwebui") {
if (this.isKeyedApi()) {
preset_names[value] = name;
const option = $('<option></option>', { value: name, text: name, selected: true });
$(this.select).append(option);
@@ -216,6 +230,10 @@ class PresetManager {
return nai_settings;
case "textgenerationwebui":
return textgenerationwebui_settings;
case "instruct":
const preset = deepClone(power_user.instruct);
preset['name'] = power_user.instruct.preset;
return preset;
default:
console.warn(`Unknown API ID ${apiId}`);
return {};
@@ -231,6 +249,7 @@ class PresetManager {
'streaming_novel',
'nai_preamble',
'model_novel',
"enabled",
];
const settings = Object.assign({}, getSettingsByApiId(this.apiId));
@@ -240,8 +259,10 @@ class PresetManager {
}
}
settings['genamt'] = amount_gen;
settings['max_length'] = max_context;
if (!this.isNonGenericApi()) {
settings['genamt'] = amount_gen;
settings['max_length'] = max_context;
}
return settings;
}
@@ -258,7 +279,7 @@ class PresetManager {
$(this.select).find(`option[value="${value}"]`).remove();
if (this.apiId == "textgenerationwebui") {
if (this.isKeyedApi()) {
preset_names.splice(preset_names.indexOf(value), 1);
} else {
delete preset_names[nameToDelete];
@@ -331,13 +352,16 @@ jQuery(async () => {
});
$(document).on("click", "[data-preset-manager-import]", async function () {
$('[data-preset-manager-file]').trigger('click');
const apiId = $(this).data("preset-manager-import");
$(`[data-preset-manager-file="${apiId}"]`).trigger('click');
});
$(document).on("change", "[data-preset-manager-file]", async function (e) {
const presetManager = getPresetManager();
const apiId = $(this).data("preset-manager-file");
const presetManager = getPresetManager(apiId);
if (!presetManager) {
console.warn(`Preset Manager not found for API: ${apiId}`);
return;
}