Merge branch 'staging' of https://github.com/SillyTavern/SillyTavern into staging

This commit is contained in:
Cohee 2023-09-21 19:30:23 +03:00
commit ad95be2500
7 changed files with 118 additions and 6 deletions

View File

@ -277,6 +277,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="range-block"> <div class="range-block">
<div class="range-block-title" data-i18n="temperature"> <div class="range-block-title" data-i18n="temperature">
Temperature Temperature
@ -1061,6 +1062,18 @@
</div> </div>
</div> </div>
<hr> <hr>
<div id="grammar_block">
<h4 data-i18n="Grammar">Grammar</h4>
<div class="range-block">
<textarea id="grammar" rows="2" class="text_pole textarea_compact monospace"></textarea>
<div class="toggle-description justifyLeft">
<span data-i18n="Type in the desired custom grammar (GBNF).">
Type in the desired custom grammar (<a href="https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md" target="_blank">GBNF</a>).
</span>
</div>
</div>
</div>
<hr>
<div class="range-block flexFlowColumn"> <div class="range-block flexFlowColumn">
<div class="range-block-title"> <div class="range-block-title">
<span data-i18n="Samplers Order">Samplers Order</span> <span data-i18n="Samplers Order">Samplers Order</span>
@ -3960,6 +3973,7 @@
<option value="1" data-i18n="After Char Defs">After Char Defs</option> <option value="1" data-i18n="After Char Defs">After Char Defs</option>
<option value="2" data-i18n="Before AN">Before AN</option> <option value="2" data-i18n="Before AN">Before AN</option>
<option value="3" data-i18n="After AN">After AN</option> <option value="3" data-i18n="After AN">After AN</option>
<option value="4" data-i18n="at Depth">at Depth</option>
</select> </select>
</small> </small>
</div> </div>
@ -4123,7 +4137,8 @@
<div title="Generate Image" class="sd_message_gen fa-solid fa-paintbrush" data-i18n="[title]Generate Image"></div> <div title="Generate Image" class="sd_message_gen fa-solid fa-paintbrush" data-i18n="[title]Generate Image"></div>
<div title="Narrate" class="mes_narrate fa-solid fa-bullhorn" data-i18n="[title]Narrate"></div> <div title="Narrate" class="mes_narrate fa-solid fa-bullhorn" data-i18n="[title]Narrate"></div>
<div title="Prompt" class="mes_prompt fa-solid fa-square-poll-horizontal " data-i18n="[title]Prompt"></div> <div title="Prompt" class="mes_prompt fa-solid fa-square-poll-horizontal " data-i18n="[title]Prompt"></div>
<div title="Create bookmark" class="mes_create_bookmark fa-regular fa-code-branch" data-i18n="[title]Create Bookmark"></div> <div title="Create bookmark" class="mes_create_bookmark fa-regular fa-solid fa-book-bookmark" data-i18n="[title]Create Bookmark"></div>
<div title="Create branch" class="mes_create_branch fa-regular fa-code-branch" data-i18n="[title]Create Branch"></div>
<div title="Copy" class="mes_copy fa-solid fa-copy " data-i18n="[title]Copy"></div> <div title="Copy" class="mes_copy fa-solid fa-copy " data-i18n="[title]Copy"></div>
</div> </div>
<div title="Open bookmark chat" class="mes_bookmark fa-solid fa-bookmark" data-i18n="[title]Open bookmark chat"></div> <div title="Open bookmark chat" class="mes_bookmark fa-solid fa-bookmark" data-i18n="[title]Open bookmark chat"></div>

View File

@ -103,7 +103,8 @@ import {
import { import {
createNewBookmark, createNewBookmark,
showBookmarksButtons showBookmarksButtons,
createBranch,
} from "./scripts/bookmarks.js"; } from "./scripts/bookmarks.js";
import { import {
@ -3285,6 +3286,14 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
} }
is_send_press = false; is_send_press = false;
} }
//prevent custom depth WI entries (which have unique random key names) from duplicating
for (let key in extension_prompts) {
if (key.includes('customDepthWI')) {
let keyname = extension_prompts[key]
delete extension_prompts[key];
}
}
//console.log('generate ending'); //console.log('generate ending');
} //generate ends } //generate ends
@ -5193,7 +5202,7 @@ export async function getChatsFromFiles(data, isGroupChat) {
let chat_dict = {}; let chat_dict = {};
let chat_list = Object.values(data).sort((a, b) => a["file_name"].localeCompare(b["file_name"])).reverse(); let chat_list = Object.values(data).sort((a, b) => a["file_name"].localeCompare(b["file_name"])).reverse();
let chat_promise = chat_list.map(({ file_name}) => { let chat_promise = chat_list.map(({ file_name }) => {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
try { try {
const endpoint = isGroupChat ? '/getgroupchat' : '/getchat'; const endpoint = isGroupChat ? '/getgroupchat' : '/getchat';
@ -6525,6 +6534,11 @@ function swipe_left() { // when we swipe left..but no generation.
} }
} }
async function branchChat(mesID) {
let name = await createBranch(mesID);
await openCharacterChat(name);
}
// when we click swipe right button // when we click swipe right button
const swipe_right = () => { const swipe_right = () => {
if (chat.length - 1 === Number(this_edit_mes_id)) { if (chat.length - 1 === Number(this_edit_mes_id)) {
@ -6705,6 +6719,8 @@ const swipe_right = () => {
} }
} }
function displayOverrideWarnings() { function displayOverrideWarnings() {
if (!this_chid || !selected_group) { if (!this_chid || !selected_group) {
$('.prompt_overridden').hide(); $('.prompt_overridden').hide();
@ -8426,6 +8442,13 @@ jQuery(async function () {
} }
}); });
$(document).on("click", ".mes_create_branch", async function () {
var selected_mes_id = $(this).closest(".mes").attr("mesid");
if (selected_mes_id !== undefined) {
branchChat(selected_mes_id);
}
});
$(document).on("click", ".mes_stop", function () { $(document).on("click", ".mes_stop", function () {
if (streamingProcessor) { if (streamingProcessor) {
streamingProcessor.abortController.abort(); streamingProcessor.abortController.abort();

View File

@ -133,6 +133,39 @@ async function saveBookmarkMenu() {
return createNewBookmark(chat.length - 1); return createNewBookmark(chat.length - 1);
} }
export async function createBranch(mesId) {
if (!chat.length) {
toastr.warning('The chat is empty.', 'Branch creation failed');
return;
}
if (mesId < 0 || mesId >= chat.length) {
toastr.warning('Invalid message ID.', 'Branch creation failed');
return;
}
const lastMes = chat[mesId];
const mainChat = selected_group ? groups?.find(x => x.id == selected_group)?.chat_id : characters[this_chid].chat;
const newMetadata = { main_chat: mainChat };
let name = `Branch #${mesId} - ${humanizedDateTime()}`
if (selected_group) {
await saveGroupBookmarkChat(selected_group, name, newMetadata, mesId);
} else {
await saveChat(name, newMetadata, mesId);
}
// append to branches list if it exists
// otherwise create it
if (typeof lastMes.extra !== 'object') {
lastMes.extra = {};
}
if (typeof lastMes.extra['branches'] !== 'object') {
lastMes.extra['branches'] = [];
}
lastMes.extra['branches'].push(name);
return name;
}
async function createNewBookmark(mesId) { async function createNewBookmark(mesId) {
if (!chat.length) { if (!chat.length) {
toastr.warning('The chat is empty.', 'Bookmark creation failed'); toastr.warning('The chat is empty.', 'Bookmark creation failed');

View File

@ -26,6 +26,7 @@ export const kai_settings = {
mirostat_tau: 5.0, mirostat_tau: 5.0,
mirostat_eta: 0.1, mirostat_eta: 0.1,
use_default_badwordsids: true, use_default_badwordsids: true,
grammar: "",
}; };
export const kai_flags = { export const kai_flags = {
@ -34,6 +35,7 @@ export const kai_flags = {
can_use_streaming: false, can_use_streaming: false,
can_use_default_badwordsids: false, can_use_default_badwordsids: false,
can_use_mirostat: false, can_use_mirostat: false,
can_use_grammar: false,
}; };
const defaultValues = Object.freeze(structuredClone(kai_settings)); const defaultValues = Object.freeze(structuredClone(kai_settings));
@ -43,6 +45,7 @@ const MIN_UNBAN_VERSION = '1.2.4';
const MIN_STREAMING_KCPPVERSION = '1.30'; const MIN_STREAMING_KCPPVERSION = '1.30';
const MIN_TOKENIZATION_KCPPVERSION = '1.41'; const MIN_TOKENIZATION_KCPPVERSION = '1.41';
const MIN_MIROSTAT_KCPPVERSION = '1.35'; const MIN_MIROSTAT_KCPPVERSION = '1.35';
const MIN_GRAMMAR_KCPPVERSION = '1.44';
const KOBOLDCPP_ORDER = [6, 0, 1, 3, 4, 2, 5]; const KOBOLDCPP_ORDER = [6, 0, 1, 3, 4, 2, 5];
export function formatKoboldUrl(value) { export function formatKoboldUrl(value) {
@ -88,6 +91,7 @@ export function loadKoboldSettings(preset) {
export function getKoboldGenerationData(finalPrompt, this_settings, this_amount_gen, this_max_context, isImpersonate, type) { export function getKoboldGenerationData(finalPrompt, this_settings, this_amount_gen, this_max_context, isImpersonate, type) {
const sampler_order = kai_settings.sampler_order || this_settings.sampler_order; const sampler_order = kai_settings.sampler_order || this_settings.sampler_order;
let generate_data = { let generate_data = {
prompt: finalPrompt, prompt: finalPrompt,
gui_settings: false, gui_settings: false,
@ -119,6 +123,7 @@ export function getKoboldGenerationData(finalPrompt, this_settings, this_amount_
mirostat_tau: kai_flags.can_use_mirostat ? kai_settings.mirostat_tau : undefined, mirostat_tau: kai_flags.can_use_mirostat ? kai_settings.mirostat_tau : undefined,
mirostat_eta: kai_flags.can_use_mirostat ? kai_settings.mirostat_eta : undefined, mirostat_eta: kai_flags.can_use_mirostat ? kai_settings.mirostat_eta : undefined,
use_default_badwordsids: kai_flags.can_use_default_badwordsids ? kai_settings.use_default_badwordsids : undefined, use_default_badwordsids: kai_flags.can_use_default_badwordsids ? kai_settings.use_default_badwordsids : undefined,
grammar: kai_flags.can_use_grammar ? kai_settings.grammar : undefined,
}; };
return generate_data; return generate_data;
} }
@ -257,6 +262,13 @@ const sliders = [
format: (val) => val, format: (val) => val,
setValue: (val) => { kai_settings.mirostat_eta = Number(val); }, setValue: (val) => { kai_settings.mirostat_eta = Number(val); },
}, },
{
name: "grammar",
sliderId: "#grammar",
counterId: "#grammar_counter_kobold",
format: (val) => val,
setValue: (val) => { kai_settings.grammar = val; },
},
]; ];
export function setKoboldFlags(version, koboldVersion) { export function setKoboldFlags(version, koboldVersion) {
@ -265,6 +277,7 @@ export function setKoboldFlags(version, koboldVersion) {
kai_flags.can_use_tokenization = canUseKoboldTokenization(koboldVersion); kai_flags.can_use_tokenization = canUseKoboldTokenization(koboldVersion);
kai_flags.can_use_default_badwordsids = canUseDefaultBadwordIds(version); kai_flags.can_use_default_badwordsids = canUseDefaultBadwordIds(version);
kai_flags.can_use_mirostat = canUseMirostat(koboldVersion); kai_flags.can_use_mirostat = canUseMirostat(koboldVersion);
kai_flags.can_use_grammar = canUseGrammar(koboldVersion);
} }
/** /**
@ -307,12 +320,28 @@ function canUseKoboldTokenization(koboldVersion) {
} else return false; } else return false;
} }
/**
* Determines if the Kobold mirostat can be used with the given version.
* @param {{result: string; version: string;}} koboldVersion KoboldAI version object.
* @returns {boolean} True if the Kobold mirostat API can be used, false otherwise.
*/
function canUseMirostat(koboldVersion) { function canUseMirostat(koboldVersion) {
if (koboldVersion && koboldVersion.result == 'KoboldCpp') { if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
return (koboldVersion.version || '0.0').localeCompare(MIN_MIROSTAT_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1; return (koboldVersion.version || '0.0').localeCompare(MIN_MIROSTAT_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
} else return false; } else return false;
} }
/**
* Determines if the Kobold grammar can be used with the given version.
* @param {{result: string; version:string;}} koboldVersion KoboldAI version object.
* @returns {boolean} True if the Kobold grammar can be used, false otherwise.
*/
function canUseGrammar(koboldVersion) {
if (koboldVersion && koboldVersion.result == 'KoboldCpp') {
return (koboldVersion.version || '0.0').localeCompare(MIN_GRAMMAR_KCPPVERSION, undefined, { numeric: true, sensitivity: 'base' }) > -1;
} else return false;
}
/** /**
* Sorts the sampler items by the given order. * Sorts the sampler items by the given order.
* @param {any[]} orderArray Sampler order array. * @param {any[]} orderArray Sampler order array.
@ -334,7 +363,7 @@ jQuery(function () {
const value = $(this).val(); const value = $(this).val();
const formattedValue = slider.format(value); const formattedValue = slider.format(value);
slider.setValue(value); slider.setValue(value);
$(slider.counterId).html(formattedValue); $(slider.counterId).text(formattedValue);
saveSettingsDebounced(); saveSettingsDebounced();
}); });
}); });

View File

@ -192,7 +192,7 @@ function selectTag(event, ui, listSelector) {
} }
// unfocus and clear the input // unfocus and clear the input
$(event.target).val("").trigger('blur'); $(event.target).val("").trigger('input');
// add tag to the UI and internal map // add tag to the UI and internal map
appendTagToList(listSelector, tag, { removable: true }); appendTagToList(listSelector, tag, { removable: true });

View File

@ -71,6 +71,7 @@ const world_info_position = {
after: 1, after: 1,
ANTop: 2, ANTop: 2,
ANBottom: 3, ANBottom: 3,
atDepth: 4,
}; };
@ -658,6 +659,9 @@ function getWorldEntry(name, data, entry) {
const uid = $(this).data("uid"); const uid = $(this).data("uid");
const value = Number($(this).val()); const value = Number($(this).val());
data.entries[uid].position = !isNaN(value) ? value : 0; data.entries[uid].position = !isNaN(value) ? value : 0;
if (value === 4) {
template.find('label[for="order"').text('Depth:')
} else { template.find('label[for="order"').text('Order:') }
// Spec v2 only supports before_char and after_char // Spec v2 only supports before_char and after_char
setOriginalDataValue(data, uid, "position", data.entries[uid].position == 0 ? 'before_char' : 'after_char'); setOriginalDataValue(data, uid, "position", data.entries[uid].position == 0 ? 'before_char' : 'after_char');
// Write the original value as extensions field // Write the original value as extensions field
@ -1154,6 +1158,13 @@ async function checkWorldInfo(chat, maxContext) {
case world_info_position.ANBottom: case world_info_position.ANBottom:
ANBottomEntries.unshift(entry.content); ANBottomEntries.unshift(entry.content);
break; break;
case world_info_position.atDepth:
//inserted one by one, unrelated to any array of items
//must have a unique value for 'key' argument
//uses the order input to specify depth
var randomNumber = Math.floor(Math.random() * 99999) + 1;
context.setExtensionPrompt(`customDepthWI-${entry.keywords}-${entry.uid}-${randomNumber}`, entry.content, 1, entry.order);
break;
default: default:
break; break;
} }

View File

@ -375,6 +375,7 @@ app.post("/generate", jsonParser, async function (request, response_generate) {
mirostat: request.body.mirostat, mirostat: request.body.mirostat,
mirostat_eta: request.body.mirostat_eta, mirostat_eta: request.body.mirostat_eta,
mirostat_tau: request.body.mirostat_tau, mirostat_tau: request.body.mirostat_tau,
grammar: request.body.grammar,
}; };
if (!!request.body.stop_sequence) { if (!!request.body.stop_sequence) {
this_settings['stop_sequence'] = request.body.stop_sequence; this_settings['stop_sequence'] = request.body.stop_sequence;