mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-10 17:14:36 +00:00
wip anti slop
This commit is contained in:
parent
65f3c68399
commit
f78f8d3d45
2 changed files with 81 additions and 20 deletions
|
@ -2544,7 +2544,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
|
|||
int tokcount = toks.size();
|
||||
if(tokcount>0)
|
||||
{
|
||||
tokcount += 2; //add some extra buffer
|
||||
tokcount += 1; //add some extra buffer
|
||||
}
|
||||
delayed_generated_tokens_limit = (tokcount>delayed_generated_tokens_limit?tokcount:delayed_generated_tokens_limit);
|
||||
banned_phrases.push_back(word);
|
||||
|
@ -3260,23 +3260,22 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
|
|||
}
|
||||
|
||||
//anti slop detection
|
||||
// for (const auto &matched : stop_sequence)
|
||||
// {
|
||||
// if (concat_output.find(matched) != std::string::npos)
|
||||
// {
|
||||
// stopper_unused_tokens = remaining_tokens;
|
||||
// remaining_tokens = 0;
|
||||
// if(allow_regular_prints)
|
||||
// {
|
||||
// auto match_clean = matched;
|
||||
// replace_all(match_clean, "\n", "\\n");
|
||||
// printf("\n(Stop sequence triggered: %s)", match_clean.c_str());
|
||||
// }
|
||||
// last_stop_reason = stop_reason::CUSTOM_STOPPER;
|
||||
// earlystopped = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
for (const auto &matched : banned_phrases)
|
||||
{
|
||||
if (concat_output.find(matched) != std::string::npos)
|
||||
{
|
||||
std::vector<int> toks;
|
||||
TokenizeString(matched, toks, file_format, false);
|
||||
int tokcount = toks.size();
|
||||
if(allow_regular_prints)
|
||||
{
|
||||
auto match_clean = matched;
|
||||
replace_all(match_clean, "\n", "\\n");
|
||||
printf("\n(Banned Phrase Detected: %s - Rewinding %d tokens)\n", match_clean.c_str(),tokcount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool earlystopped = false;
|
||||
if(!inputs.bypass_eos_token && inputs.allow_eos_token && (id==eosID || (id==eotID && id!=-1)))
|
||||
|
|
66
klite.embd
66
klite.embd
|
@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
|
|||
-->
|
||||
|
||||
<script>
|
||||
const LITEVER = 178;
|
||||
const LITEVER = 179;
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
var localflag = true;
|
||||
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
|
||||
|
@ -4258,6 +4258,7 @@ Current version indicated by LITEVER below.
|
|||
var current_anotetemplate = "[Author\'s note: <|>]";
|
||||
var extrastopseq = "";
|
||||
var tokenbans = "";
|
||||
var phrasebans = "";
|
||||
var anote_strength = 320; //distance from end
|
||||
var newlineaftermemory = true;
|
||||
var current_wi = []; //each item stores a wi object.
|
||||
|
@ -6092,6 +6093,7 @@ Current version indicated by LITEVER below.
|
|||
//extra unofficial fields for the story
|
||||
new_save_storyobj.extrastopseq = extrastopseq;
|
||||
new_save_storyobj.tokenbans = tokenbans;
|
||||
new_save_storyobj.phrasebans = phrasebans;
|
||||
new_save_storyobj.anotestr = anote_strength;
|
||||
new_save_storyobj.wisearchdepth = wi_searchdepth;
|
||||
new_save_storyobj.wiinsertlocation = wi_insertlocation;
|
||||
|
@ -6283,6 +6285,7 @@ Current version indicated by LITEVER below.
|
|||
let old_current_wi = current_wi;
|
||||
let old_extrastopseq = extrastopseq;
|
||||
let old_tokenbans = tokenbans;
|
||||
let old_phrasebans = phrasebans;
|
||||
let old_notes = personal_notes;
|
||||
let old_regexreplace_data = regexreplace_data;
|
||||
let old_placeholder_tags_data = placeholder_tags_data;
|
||||
|
@ -6342,6 +6345,10 @@ Current version indicated by LITEVER below.
|
|||
{
|
||||
tokenbans = storyobj.tokenbans;
|
||||
}
|
||||
if(storyobj.phrasebans)
|
||||
{
|
||||
phrasebans = storyobj.phrasebans;
|
||||
}
|
||||
if (storyobj.anotestr) {
|
||||
anote_strength = storyobj.anotestr;
|
||||
}
|
||||
|
@ -6439,6 +6446,7 @@ Current version indicated by LITEVER below.
|
|||
extrastopseq = old_extrastopseq;
|
||||
regexreplace_data = old_regexreplace_data;
|
||||
tokenbans = old_tokenbans;
|
||||
phrasebans = old_phrasebans;
|
||||
placeholder_tags_data = old_placeholder_tags_data;
|
||||
}
|
||||
|
||||
|
@ -7996,7 +8004,7 @@ Current version indicated by LITEVER below.
|
|||
|
||||
function expand_tokens_section(targetid)
|
||||
{
|
||||
let tablist = ["expandregexreplace","expandtokenbans","expandlogitbias","expandplaceholdertags"];
|
||||
let tablist = ["expandregexreplace","expandtokenbans","expandphrasebans","expandlogitbias","expandplaceholdertags"];
|
||||
|
||||
for(let i=0;i<tablist.length;++i)
|
||||
{
|
||||
|
@ -8107,6 +8115,23 @@ Current version indicated by LITEVER below.
|
|||
},false);
|
||||
}
|
||||
|
||||
function add_phrase_ban()
|
||||
{
|
||||
inputBox("Enter a string to be banned (e.g. Slop text to remove). If it's generated, the AI backtracks and tries something else.","Add Banned Phrase String","","Enter String To Ban",()=>{
|
||||
let userinput = getInputBoxValue();
|
||||
if(userinput.trim()!="")
|
||||
{
|
||||
let ov = document.getElementById("phrasebans").value;
|
||||
if(ov!="")
|
||||
{
|
||||
ov += "||$||";
|
||||
}
|
||||
ov += userinput.trim();
|
||||
document.getElementById("phrasebans").value = ov;
|
||||
}
|
||||
},false);
|
||||
}
|
||||
|
||||
var msgboxOnDone = hide_msgbox;
|
||||
function hide_msgbox() {
|
||||
//hide msgbox ONLY
|
||||
|
@ -10642,6 +10667,7 @@ Current version indicated by LITEVER below.
|
|||
anote_strength = document.getElementById("anote_strength").value;
|
||||
extrastopseq = document.getElementById("extrastopseq").value;
|
||||
tokenbans = document.getElementById("tokenbans").value;
|
||||
phrasebans = document.getElementById("phrasebans").value;
|
||||
newlineaftermemory = (document.getElementById("newlineaftermemory").checked?true:false);
|
||||
try
|
||||
{
|
||||
|
@ -10910,6 +10936,7 @@ Current version indicated by LITEVER below.
|
|||
current_wi = [];
|
||||
extrastopseq = "";
|
||||
tokenbans = "";
|
||||
phrasebans = "";
|
||||
anote_strength = 320;
|
||||
logitbiasdict = {};
|
||||
wi_searchdepth = 0;
|
||||
|
@ -12475,6 +12502,24 @@ Current version indicated by LITEVER below.
|
|||
return seqs;
|
||||
}
|
||||
|
||||
function get_phrase_bans()
|
||||
{
|
||||
let seqs = [];
|
||||
if (phrasebans != "") {
|
||||
let rep = replaceAll(phrasebans, "\\n", "\n");
|
||||
let srep = rep.split("||$||");
|
||||
if (srep.length > 0 && !seqs) {
|
||||
seqs = [];
|
||||
}
|
||||
for (let i = 0; i < srep.length; ++i) {
|
||||
if (srep[i] && srep[i] != "") {
|
||||
seqs.push(srep[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return seqs;
|
||||
}
|
||||
|
||||
function cleanup_story_completion(resp)
|
||||
{
|
||||
if(gametext_arr.length>0)
|
||||
|
@ -12532,6 +12577,7 @@ Current version indicated by LITEVER below.
|
|||
submit_payload.params.dynatemp_exponent = localsettings.dynatemp_exponent;
|
||||
submit_payload.params.smoothing_factor = localsettings.smoothing_factor;
|
||||
submit_payload.params.banned_tokens = get_token_bans();
|
||||
submit_payload.params.banned_phrases = get_phrase_bans();
|
||||
submit_payload.params.render_special = localsettings.render_special_tags;
|
||||
}
|
||||
if(custom_kobold_endpoint != "" && is_using_kcpp_with_dry() && localsettings.dry_multiplier > 0)
|
||||
|
@ -16436,6 +16482,7 @@ Current version indicated by LITEVER below.
|
|||
document.getElementById("anote_strength").value = anote_strength;
|
||||
document.getElementById("extrastopseq").value = extrastopseq;
|
||||
document.getElementById("tokenbans").value = tokenbans;
|
||||
document.getElementById("phrasebans").value = phrasebans;
|
||||
document.getElementById("newlineaftermemory").checked = (newlineaftermemory?true:false);
|
||||
document.getElementById("logitbiastxtarea").value = JSON.stringify(logitbiasdict,null,2);
|
||||
|
||||
|
@ -16459,6 +16506,7 @@ Current version indicated by LITEVER below.
|
|||
{
|
||||
document.getElementById("nologitbias").classList.add("hidden");
|
||||
document.getElementById("notokenbans").classList.add("hidden");
|
||||
document.getElementById("nophrasebans").classList.add("hidden");
|
||||
if(is_using_kcpp_with_added_memory())
|
||||
{
|
||||
document.getElementById("newlogitbiasstringtogglesection").classList.remove("hidden");
|
||||
|
@ -16471,6 +16519,7 @@ Current version indicated by LITEVER below.
|
|||
{
|
||||
document.getElementById("nologitbias").classList.remove("hidden");
|
||||
document.getElementById("notokenbans").classList.remove("hidden");
|
||||
document.getElementById("nophrasebans").classList.remove("hidden");
|
||||
document.getElementById("newlogitbiasstringtogglesection").classList.add("hidden");
|
||||
document.getElementById("newlogitbiasstringtoggle").checked = false;
|
||||
}
|
||||
|
@ -19164,6 +19213,19 @@ Current version indicated by LITEVER below.
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div style="padding:3px;" class="justifyleft settinglabel">Phrase Ban (Anti-Slop) <span class="helpicon">?<span
|
||||
class="helptext">Prevents specific phrases from being generated by backtracking and regenerating when they appear. If you want multiple sequences, separate them with the following delimiter: ||$||</span></span>
|
||||
<button type="button" title="Phrase Ban (Anti-Slop)" class="btn btn-primary" style="font-size:12px;padding:2px 2px;" onclick="expand_tokens_section('expandphrasebans')">Expand Section</button>
|
||||
</div>
|
||||
<div id="expandphrasebans" class="hidden">
|
||||
<div class="color_red hidden" id="nophrasebans">Phrase Ban (Anti-Slop) may be unavailable.</div>
|
||||
<div style="color:#ffffff;">Prevents specific phrases from being generated by backtracking and regenerating when they appear. If you want multiple sequences, separate them with the following delimiter: ||$||<br></div>
|
||||
<div style="display: flex; column-gap: 4px; margin-bottom: 4px;">
|
||||
<input class="form-control stopseqbox inlineinput" type="text" placeholder="None" value="" id="phrasebans">
|
||||
<button type="button" class="btn btn-primary" style="width:90px;padding:6px 6px;" onclick="add_phrase_ban()">Add New</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="padding:3px;" class="justifyleft settinglabel">Regex Replace <span class="helpicon">?<span
|
||||
class="helptext">Allows transforming incoming text with regex patterns, modifying all matches. Replacements will be applied in sequence.</span></span>
|
||||
<button type="button" title="Regex Replace" class="btn btn-primary" style="font-size:12px;padding:2px 2px;" onclick="expand_tokens_section('expandregexreplace')">Expand Section</button>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue