Skip to content

Commit

Permalink
added stop sequences for horde
Browse files Browse the repository at this point in the history
  • Loading branch information
Concedo authored and Concedo committed Oct 24, 2023
1 parent 8b2d997 commit 073b07b
Showing 1 changed file with 57 additions and 48 deletions.
105 changes: 57 additions & 48 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8119,6 +8119,56 @@
}
}

function get_stop_sequences() //the input object may not always be the same!
{
let seqs = [];
if (localsettings.opmode == 2) //stop on new action found
{
seqs = ["\n\> "];
}
if (localsettings.opmode == 3) //stop on selfname found
{
seqs = [localsettings.chatname + "\:",("\n" + localsettings.chatname + " ")];

//for multichat, everyone else becomes a stopper token
if (localsettings.chatopponent!="" && localsettings.chatopponent.includes("||$||")) {
let coarr = localsettings.chatopponent.split("||$||");
coarr = coarr.filter(x => (x && x != ""));
coarr = coarr.map(x => x.trim());
for (let n = 0; n < coarr.length; ++n) {
seqs.push(coarr[n] + "\:");
}
}
else
{
if(localsettings.chatopponent!="")
{
seqs.push("\n"+localsettings.chatopponent + "\: ");
}
}
}
if (localsettings.opmode == 4) //stop on selfname found
{
let st = get_instruct_starttag(true);
let et = get_instruct_endtag(true);
seqs = [st, et];
}
if (extrastopseq != "") {
let rep = replaceAll(extrastopseq, "\\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 dispatch_submit_generation(submit_payload, input_was_empty) //if input is not empty, always unban eos
{
console.log(submit_payload);
Expand Down Expand Up @@ -8146,49 +8196,7 @@

//for vesion 1.2.2 and later, send stopper tokens for chat and instruct
if (kobold_endpoint_version && kobold_endpoint_version != "" && compare_version_str(kobold_endpoint_version, "1.2.1") > 0) {
if (localsettings.opmode == 2) //stop on new action found
{
submit_payload.stop_sequence = ["\n\> "];
}
if (localsettings.opmode == 3) //stop on selfname found
{
submit_payload.stop_sequence = [localsettings.chatname + "\:",("\n" + localsettings.chatname + " ")];

//for multichat, everyone else becomes a stopper token
if (localsettings.chatopponent!="" && localsettings.chatopponent.includes("||$||")) {
let coarr = localsettings.chatopponent.split("||$||");
coarr = coarr.filter(x => (x && x != ""));
coarr = coarr.map(x => x.trim());
for (let n = 0; n < coarr.length; ++n) {
submit_payload.stop_sequence.push(coarr[n] + "\:");
}
}
else
{
if(localsettings.chatopponent!="")
{
submit_payload.stop_sequence.push("\n"+localsettings.chatopponent + "\: ");
}
}
}
if (localsettings.opmode == 4) //stop on selfname found
{
let st = get_instruct_starttag(true);
let et = get_instruct_endtag(true);
submit_payload.stop_sequence = [st, et];
}
if (extrastopseq != "") {
let rep = replaceAll(extrastopseq, "\\n", "\n");
let srep = rep.split("||$||");
if (srep.length > 0 && !submit_payload.stop_sequence) {
submit_payload.stop_sequence = [];
}
for (let i = 0; i < srep.length; ++i) {
if (srep[i] && srep[i] != "") {
submit_payload.stop_sequence.push(srep[i]);
}
}
}
submit_payload.stop_sequence = get_stop_sequences();
}

//version 1.2.4 and later supports unban tokens
Expand Down Expand Up @@ -8497,10 +8505,13 @@
subpostheaders['Client-Agent'] = clientagenttouse;
}

//horde supports unban tokens
if(submit_payload.params)
{
//horde supports unban tokens
submit_payload.params.use_default_badwordsids = determine_if_ban_eos(input_was_empty);

//horde now supports stopping sequences
submit_payload.params.stop_sequence = get_stop_sequences();
}

last_request_str = JSON.stringify(submit_payload);
Expand Down Expand Up @@ -10077,7 +10088,7 @@
document.getElementById("anote_strength").value = anote_strength;
document.getElementById("extrastopseq").value = extrastopseq;
document.getElementById("newlineaftermemory").checked = (newlineaftermemory?true:false);
if(custom_kobold_endpoint!="")
if(custom_kobold_endpoint!="" || !is_using_custom_ep() )
{
document.getElementById("noextrastopseq").classList.add("hidden");
}
Expand Down Expand Up @@ -11810,13 +11821,11 @@
<option value="0">Immediate</option>
</select>
<br><br>
<div class="justifyleft settinglabel">Extra Stopping Sequence (Kobold API Only) <span class="helpicon">?<span
<div class="justifyleft settinglabel">Extra Stopping Sequences <span class="helpicon">?<span
class="helptext">Triggers the text generator to stop generating early if this sequence appears, in addition to default stop sequences. If you want multiple sequences, separate them with the following delimiter: ||$||</span></span></div>
<div class="color_red hidden" id="noextrastopseq">Stop Sequences may be unavailable.</div>
<input class="form-control" type="text" placeholder="None" value="" id="extrastopseq">



<br>
<div class="popupfooter">
<button type="button" class="btn btn-primary" onclick="confirm_memory()">OK</button>
Expand Down

0 comments on commit 073b07b

Please sign in to comment.