Add instruct presets

This commit is contained in:
SillyLossy
2023-05-10 23:51:59 +03:00
parent 38afc89b14
commit ee8ae7e9c6
7 changed files with 121 additions and 20 deletions

View File

@ -1180,7 +1180,7 @@
Custom Chat Separator Custom Chat Separator
</h4> </h4>
<div> <div>
<input id="custom_chat_separator" class="text_pole" type="text" placeholder="&lt;START&gt;" maxlength="100" /> <input id="custom_chat_separator" class="text_pole textarea_compact" type="text" placeholder="&lt;START&gt;" maxlength="100" />
</div> </div>
</div> </div>
<div> <div>
@ -1189,22 +1189,22 @@
<span class="note-link-span">?</span> <span class="note-link-span">?</span>
</a> </a>
</h4> </h4>
<label for="instruct_enabled" class="checkbox_label"> <div>
<input id="instruct_enabled" type="checkbox" /> <label for="instruct_enabled" class="checkbox_label">
Enabled <input id="instruct_enabled" type="checkbox" />
</label> Enabled
<label for="instruct_wrap" class="checkbox_label"> </label>
<input id="instruct_wrap" type="checkbox" /> <label for="instruct_wrap" class="checkbox_label">
Wrap Sequences with Newline <input id="instruct_wrap" type="checkbox" />
</label> Wrap Sequences with Newline
<label for="instruct_names" class="checkbox_label"> </label>
<input id="instruct_names" type="checkbox" /> <label for="instruct_names" class="checkbox_label">
Include Names <input id="instruct_names" type="checkbox" />
</label> Include Names
</label>
</div>
<label for="instruct_presets">Presets</label> <label for="instruct_presets">Presets</label>
<select id="instruct_presets"> <select id="instruct_presets"></select>
<option>--- UNDER CONSTRUCTION ---</option>
</select>
<label> <label>
System Prompt System Prompt
</label> </label>
@ -1269,7 +1269,7 @@
<span class="note-link-span">?</span> <span class="note-link-span">?</span>
</a> </a>
</div> </div>
<input id="token_padding" class="text_pole" type="number" min="-2048" max="2048" /> <input id="token_padding" class="text_pole textarea_compact" type="number" min="-2048" max="2048" />
</div> </div>
<label class="checkbox_label" for="always-force-name2-checkbox"> <label class="checkbox_label" for="always-force-name2-checkbox">
<input id="always-force-name2-checkbox" type="checkbox" /> <input id="always-force-name2-checkbox" type="checkbox" />
@ -1306,11 +1306,11 @@
<div class="multigen_settings_block"> <div class="multigen_settings_block">
<label for="multigen_1st_chunk"> <label for="multigen_1st_chunk">
<small>First chunk (tokens)</small> <small>First chunk (tokens)</small>
<input id="multigen_first_chunk" type="number" class="text_pole" min="1" max="512" /> <input id="multigen_first_chunk" type="number" class="text_pole textarea_compact" min="1" max="512" />
</label> </label>
<label for="multigen_next_chunk"> <label for="multigen_next_chunk">
<small>Next chunks (tokens)</small> <small>Next chunks (tokens)</small>
<input id="multigen_next_chunks" type="number" class="text_pole" min="1" max="512" /> <input id="multigen_next_chunks" type="number" class="text_pole textarea_compact" min="1" max="512" />
</label> </label>
</div> </div>
</div> </div>

View File

@ -0,0 +1,9 @@
{
"name": "Alpaca",
"system_prompt": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.",
"system_sequence": "",
"stop_sequence": "",
"input_sequence": "### Instruction:",
"output_sequence": "### Response:",
"wrap": true
}

View File

@ -0,0 +1,9 @@
{
"name": "Koala",
"system_prompt": "Write {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.",
"system_sequence": "BEGINNING OF CONVERSATION:",
"stop_sequence": "",
"input_sequence": "USER: ",
"output_sequence": "GPT: ",
"wrap": true
}

View File

@ -0,0 +1,9 @@
{
"name": "Metharme",
"system_prompt": "Write {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.",
"system_sequence": "<|system|>",
"stop_sequence": "</s>",
"input_sequence": "<|user|>",
"output_sequence": "<|model|>",
"wrap": false
}

View File

@ -0,0 +1,9 @@
{
"name": "WizardLM",
"system_prompt": "Write {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}.",
"system_sequence": "",
"stop_sequence": "",
"input_sequence": "### Instruction:",
"output_sequence": "### Response:",
"wrap": true
}

View File

@ -121,10 +121,12 @@ let power_user = {
stop_sequence: '', stop_sequence: '',
input_sequence: '### Instruction:', input_sequence: '### Instruction:',
output_sequence: '### Response:', output_sequence: '### Response:',
preset: 'Alpaca',
} }
}; };
let themes = []; let themes = [];
let instruct_presets = [];
const storage_keys = { const storage_keys = {
fast_ui_mode: "TavernAI_fast_ui_mode", fast_ui_mode: "TavernAI_fast_ui_mode",
@ -447,6 +449,10 @@ function loadPowerUserSettings(settings, data) {
themes = data.themes; themes = data.themes;
} }
if (data.instruct !== undefined) {
instruct_presets = data.instruct;
}
// These are still local storage // These are still local storage
const fastUi = localStorage.getItem(storage_keys.fast_ui_mode); const fastUi = localStorage.getItem(storage_keys.fast_ui_mode);
const waifuMode = localStorage.getItem(storage_keys.waifuMode); const waifuMode = localStorage.getItem(storage_keys.waifuMode);
@ -556,6 +562,38 @@ function loadInstructMode() {
saveSettingsDebounced(); saveSettingsDebounced();
}); });
}); });
instruct_presets.forEach((preset) => {
const name = preset.name;
const option = document.createElement('option');
option.value = name;
option.innerText = name;
option.selected = name === power_user.instruct.preset;
$('#instruct_presets').append(option);
});
$('#instruct_presets').on('change', function () {
const name = $(this).find(':selected').val();
const preset = instruct_presets.find(x => x.name === name);
if (!preset) {
return;
}
power_user.instruct.preset = name;
controls.forEach(control => {
if (preset[control.property] !== undefined) {
power_user.instruct[control.property] = preset[control.property];
const $element = $(`#${control.id}`);
if (control.isCheckbox) {
$element.prop('checked', power_user.instruct[control.property]).trigger('input');
} else {
$element.val(power_user.instruct[control.property]).trigger('input');
}
}
});
});
} }
export function formatInstructModeChat(name, mes, isUser) { export function formatInstructModeChat(name, mes, isUser) {

View File

@ -185,7 +185,8 @@ const directories = {
thumbnailsBg: 'thumbnails/bg/', thumbnailsBg: 'thumbnails/bg/',
thumbnailsAvatar: 'thumbnails/avatar/', thumbnailsAvatar: 'thumbnails/avatar/',
themes: 'public/themes', themes: 'public/themes',
extensions: 'public/scripts/extensions' extensions: 'public/scripts/extensions',
instruct: 'public/instruct',
}; };
// CSRF Protection // // CSRF Protection //
@ -1143,6 +1144,7 @@ app.post('/getsettings', jsonParser, (request, response) => { //Wintermute's cod
const textgenerationwebui_presets = []; const textgenerationwebui_presets = [];
const textgenerationwebui_preset_names = []; const textgenerationwebui_preset_names = [];
const themes = []; const themes = [];
const instruct = [];
const settings = fs.readFileSync('public/settings.json', 'utf8', (err, data) => { const settings = fs.readFileSync('public/settings.json', 'utf8', (err, data) => {
if (err) return response.sendStatus(500); if (err) return response.sendStatus(500);
@ -1269,6 +1271,30 @@ app.post('/getsettings', jsonParser, (request, response) => { //Wintermute's cod
} }
}) })
// Instruct files
const instructFiles = fs
.readdirSync(directories.instruct)
.filter(x => path.parse(x).ext == '.json')
.sort();
instructFiles.forEach(item => {
const file = fs.readFileSync(
path.join(directories.instruct, item),
'utf-8',
(err, data) => {
if (err) return response.sendStatus(500);
return data;
}
);
try {
instruct.push(json5.parse(file));
}
catch {
// skip
}
});
response.send({ response.send({
settings, settings,
koboldai_settings, koboldai_settings,
@ -1281,6 +1307,7 @@ app.post('/getsettings', jsonParser, (request, response) => { //Wintermute's cod
textgenerationwebui_presets, textgenerationwebui_presets,
textgenerationwebui_preset_names, textgenerationwebui_preset_names,
themes, themes,
instruct,
enable_extensions: enableExtensions, enable_extensions: enableExtensions,
}); });
}); });