mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-09 08:38:53 +01:00
commit
728ffd1628
@ -857,7 +857,7 @@
|
||||
<small>3</small>
|
||||
</div>
|
||||
<div data-id="4">
|
||||
<span data-i18n="Typical Sampling">Typical Sampling</span>
|
||||
<span data-i18n="Typical Sampling">Typical P Sampling</span>
|
||||
<small>4</small>
|
||||
</div>
|
||||
<div data-id="5">
|
||||
@ -901,6 +901,21 @@
|
||||
<textarea id="nai_banned_tokens" class="text_pole textarea_compact" name="nai_banned_tokens" rows="2" placeholder=""></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block">
|
||||
<div class="range-block-title title_restorable">
|
||||
<span data-i18n="Logit Bias">Logit Bias</span>
|
||||
<div id="novelai_logit_bias_new_entry" class="menu_button menu_button_icon">
|
||||
<i class="fa-xs fa-solid fa-plus"></i>
|
||||
<small data-i18n="Add">Add</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="toggle-description justifyLeft" data-i18n="Helps to ban or reenforce the usage of certain words">
|
||||
Helps to ban or reinforce the usage of certain tokens.
|
||||
</div>
|
||||
<div class="flex-container flexFlowColumn wide100p">
|
||||
<div class="novelai_logit_bias_list"></div>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="range-block">
|
||||
<div class="range-block-title justifyLeft" data-i18n="CFG Scale">
|
||||
@ -3783,6 +3798,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="novelai_logit_bias_template" class="template_element">
|
||||
<div class="novelai_logit_bias_form">
|
||||
<input class="novelai_logit_bias_text text_pole" data-i18n="[placeholder]Type here..." placeholder="type here..." />
|
||||
<input class="novelai_logit_bias_value text_pole" type="number" min="-2" value="0" max="2" step="0.01" />
|
||||
<i class="menu_button fa-solid fa-xmark novelai_logit_bias_remove"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="completion_prompt_manager_popup" class="drawer-content" style="display:none;">
|
||||
<div id="completion_prompt_manager_popup_inspect">
|
||||
<h3>Inspect</h3>
|
||||
|
@ -9,7 +9,10 @@ import {
|
||||
} from "../script.js";
|
||||
import { getCfg } from "./extensions/cfg/util.js";
|
||||
import { MAX_CONTEXT_DEFAULT, tokenizers } from "./power-user.js";
|
||||
import { getStringHash } from "./utils.js";
|
||||
import {
|
||||
getStringHash,
|
||||
uuidv4
|
||||
} from "./utils.js";
|
||||
|
||||
export {
|
||||
nai_settings,
|
||||
@ -49,6 +52,7 @@ const nai_settings = {
|
||||
cfg_uc: '',
|
||||
banned_tokens: '',
|
||||
order: default_order,
|
||||
logit_bias: [],
|
||||
};
|
||||
|
||||
const nai_tiers = {
|
||||
@ -60,6 +64,7 @@ const nai_tiers = {
|
||||
|
||||
let novel_data = null;
|
||||
let badWordsCache = {};
|
||||
let biasCache = undefined;
|
||||
|
||||
export function setNovelData(data) {
|
||||
novel_data = data;
|
||||
@ -114,6 +119,7 @@ function loadNovelPreset(preset) {
|
||||
nai_settings.cfg_uc = preset.cfg_uc || '';
|
||||
nai_settings.banned_tokens = preset.banned_tokens || '';
|
||||
nai_settings.order = preset.order || default_order;
|
||||
nai_settings.logit_bias = preset.logit_bias || [];
|
||||
loadNovelSettingsUi(nai_settings);
|
||||
}
|
||||
|
||||
@ -147,6 +153,7 @@ function loadNovelSettings(settings) {
|
||||
nai_settings.cfg_uc = settings.cfg_uc || '';
|
||||
nai_settings.banned_tokens = settings.banned_tokens || '';
|
||||
nai_settings.order = settings.order || default_order;
|
||||
nai_settings.logit_bias = settings.logit_bias || [];
|
||||
loadNovelSettingsUi(nai_settings);
|
||||
}
|
||||
|
||||
@ -189,6 +196,7 @@ function loadNovelSettingsUi(ui_settings) {
|
||||
|
||||
$("#streaming_novel").prop('checked', ui_settings.streaming_novel);
|
||||
sortItemsByOrder(ui_settings.order);
|
||||
displayLogitBias(ui_settings.logit_bias);
|
||||
}
|
||||
|
||||
const sliders = [
|
||||
@ -398,6 +406,12 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
|
||||
const prefix = selectPrefix(nai_settings.prefix, finalPrompt);
|
||||
const cfgSettings = getCfg();
|
||||
|
||||
let logitBias = [];
|
||||
if (tokenizerType !== tokenizers.NONE && Array.isArray(nai_settings.logit_bias) && nai_settings.logit_bias.length) {
|
||||
logitBias = biasCache || calculateLogitBias();
|
||||
biasCache = logitBias;
|
||||
}
|
||||
|
||||
return {
|
||||
"input": finalPrompt,
|
||||
"model": nai_settings.model_novel,
|
||||
@ -418,10 +432,11 @@ export function getNovelGenerationData(finalPrompt, this_settings, this_amount_g
|
||||
"mirostat_lr": parseFloat(nai_settings.mirostat_lr),
|
||||
"mirostat_tau": parseFloat(nai_settings.mirostat_tau),
|
||||
"cfg_scale": cfgSettings?.guidanceScale ?? parseFloat(nai_settings.cfg_scale),
|
||||
"cfg_uc": cfgSettings?.negativePrompt ?? nai_settings.cfg_uc ?? "",
|
||||
"cfg_uc": cfgSettings?.negativePrompt ?? nai_settings.cfg_uc ?? "",
|
||||
"phrase_rep_pen": nai_settings.phrase_rep_pen,
|
||||
"stop_sequences": stopSequences,
|
||||
"bad_words_ids": badWordIds,
|
||||
"logit_bias_exp": logitBias,
|
||||
"generate_until_sentence": true,
|
||||
"use_cache": false,
|
||||
"use_string": true,
|
||||
@ -487,6 +502,76 @@ function saveSamplingOrder() {
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function displayLogitBias(logit_bias) {
|
||||
if (!Array.isArray(logit_bias)) {
|
||||
console.log('Logit bias set not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$('.novelai_logit_bias_list').empty();
|
||||
|
||||
for (const entry of logit_bias) {
|
||||
if (entry) {
|
||||
createLogitBiasListItem(entry);
|
||||
}
|
||||
}
|
||||
|
||||
biasCache = undefined;
|
||||
}
|
||||
|
||||
function createNewLogitBiasEntry() {
|
||||
const entry = { id: uuidv4(), text: '', value: 0 };
|
||||
nai_settings.logit_bias.push(entry);
|
||||
biasCache = undefined;
|
||||
createLogitBiasListItem(entry);
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function createLogitBiasListItem(entry) {
|
||||
const id = entry.id;
|
||||
const template = $('#novelai_logit_bias_template .novelai_logit_bias_form').clone();
|
||||
template.data('id', id);
|
||||
template.find('.novelai_logit_bias_text').val(entry.text).on('input', function () {
|
||||
entry.text = $(this).val();
|
||||
biasCache = undefined;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
template.find('.novelai_logit_bias_value').val(entry.value).on('input', function () {
|
||||
entry.value = Number($(this).val());
|
||||
biasCache = undefined;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
template.find('.novelai_logit_bias_remove').on('click', function () {
|
||||
$(this).closest('.novelai_logit_bias_form').remove();
|
||||
const index = nai_settings.logit_bias.indexOf(entry);
|
||||
if (index > -1) {
|
||||
nai_settings.logit_bias.splice(index, 1);
|
||||
}
|
||||
biasCache = undefined;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
$('.novelai_logit_bias_list').prepend(template);
|
||||
}
|
||||
|
||||
function calculateLogitBias() {
|
||||
const bias_preset = nai_settings.logit_bias;
|
||||
|
||||
if (!Array.isArray(bias_preset) || bias_preset.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const clio = nai_settings.model_novel.includes('clio');
|
||||
const kayra = nai_settings.model_novel.includes('kayra');
|
||||
const tokenizerType = kayra ? tokenizers.NERD2 : (clio ? tokenizers.NERD : tokenizers.NONE);
|
||||
|
||||
return bias_preset.filter(b => b.text?.length > 0).map(bias => ({
|
||||
bias: bias.value,
|
||||
ensure_sequence_finish: false,
|
||||
generate_once: false,
|
||||
sequence: getTextTokens(tokenizerType, bias.text)
|
||||
}));
|
||||
}
|
||||
|
||||
export async function generateNovelWithStreaming(generate_data, signal) {
|
||||
const response = await fetch('/generate_novelai', {
|
||||
headers: getRequestHeaders(),
|
||||
@ -590,4 +675,6 @@ $(document).ready(function () {
|
||||
console.log('Sampler toggled:', $item.data('id'), !isEnabled);
|
||||
saveSamplingOrder();
|
||||
});
|
||||
|
||||
$("#novelai_logit_bias_new_entry").on("click", createNewLogitBiasEntry);
|
||||
});
|
||||
|
@ -4590,6 +4590,41 @@ toolcool-color-picker {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.novelai_logit_bias_form {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
column-gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.novelai_logit_bias_text,
|
||||
.novelai_logit_bias_value {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.novelai_logit_bias_list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.novelai_logit_bias_list:empty {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.novelai_logit_bias_list:empty::before {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
content: "No items";
|
||||
font-weight: bolder;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
opacity: 0.8;
|
||||
min-height: 2.5rem;
|
||||
}
|
||||
|
||||
/*used to fix smallness of certain FontAwesome glyph which break button squareness*/
|
||||
/*currently used on: CharList Import*/
|
||||
|
||||
|
12
server.js
12
server.js
@ -1853,7 +1853,7 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
|
||||
const novelai = require('./src/novelai');
|
||||
const isNewModel = (request.body.model.includes('clio') || request.body.model.includes('kayra'));
|
||||
const isKrake = request.body.model.includes('krake');
|
||||
const badWordsList = isNewModel ? novelai.badWordsList : (isKrake ? novelai.krakeBadWordsList : novelai.euterpeBadWordsList);
|
||||
const badWordsList = (isNewModel ? novelai.badWordsList : (isKrake ? novelai.krakeBadWordsList : novelai.euterpeBadWordsList)).slice();
|
||||
|
||||
// Add customized bad words for Clio and Kayra
|
||||
if (isNewModel && Array.isArray(request.body.bad_words_ids)) {
|
||||
@ -1864,6 +1864,13 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
|
||||
}
|
||||
}
|
||||
|
||||
// Add default biases for dinkus and asterism
|
||||
const logit_bias_exp = isNewModel ? novelai.logitBiasExp.slice() : null;
|
||||
|
||||
if (Array.isArray(logit_bias_exp) && Array.isArray(request.body.logit_bias_exp)) {
|
||||
logit_bias_exp.push(...request.body.logit_bias_exp);
|
||||
}
|
||||
|
||||
const data = {
|
||||
"input": request.body.input,
|
||||
"model": request.body.model,
|
||||
@ -1889,9 +1896,8 @@ app.post("/generate_novelai", jsonParser, async function (request, response_gene
|
||||
"cfg_uc": request.body.cfg_uc,
|
||||
"phrase_rep_pen": request.body.phrase_rep_pen,
|
||||
"stop_sequences": request.body.stop_sequences,
|
||||
//"stop_sequences": {{187}},
|
||||
"bad_words_ids": badWordsList,
|
||||
"logit_bias_exp": isNewModel ? novelai.logitBiasExp : null,
|
||||
"logit_bias_exp": logit_bias_exp,
|
||||
//generate_until_sentence = true;
|
||||
"use_cache": request.body.use_cache,
|
||||
"use_string": true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user