Skip to content

Commit 5b2d93a

Browse files
committed
updated lite and colab, added logit bias support to lite
1 parent 4d6d967 commit 5b2d93a

File tree

2 files changed

+76
-35
lines changed

2 files changed

+76
-35
lines changed

colab.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"#@title <-- Tap this if you play on Mobile { display-mode: \"form\" }\n",
3535
"%%html\n",
3636
"<b>Press play on the music player to keep the tab alive, then start KoboldCpp below</b><br/>\n",
37-
"<audio autoplay=\"\" src=\"https://raw.githubusercontent.com/KoboldAI/KoboldAI-Client/main/colab/silence.m4a\" controls>"
37+
"<audio autoplay=\"\" src=\"https://raw.githubusercontent.com/KoboldAI/KoboldAI-Client/main/colab/silence.m4a\" loop controls>"
3838
]
3939
},
4040
{

klite.embd

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It requires no dependencies, installation or setup.
66
Just copy this single static HTML file anywhere and open it in a browser, or from a webserver.
77
Please go to https://github.com/LostRuins/lite.koboldai.net for updates on Kobold Lite.
88
Kobold Lite is under the AGPL v3.0 License unless otherwise exempted. Please do not remove this line.
9-
Current version: 101
9+
Current version: 102
1010
-Concedo
1111
-->
1212

@@ -316,6 +316,11 @@ Current version: 101
316316
width: 94px;
317317
padding: 6px 3px;
318318
}
319+
.stopseqbox
320+
{
321+
display: inline;
322+
width: calc(100% - 110px);
323+
}
319324

320325
#popuptitlebar {
321326
padding: 10px;
@@ -3294,6 +3299,7 @@ Current version: 101
32943299
var globalabortcontroller = null;
32953300
var passed_ai_warning_local = false;
32963301
var welcome = "";
3302+
var logitbiasdict = {};
32973303

32983304
var localsettings = {
32993305
my_api_key: "0000000000", //put here so it can be saved and loaded in persistent mode
@@ -4531,6 +4537,7 @@ Current version: 101
45314537
new_save_storyobj.anotestr = anote_strength;
45324538
new_save_storyobj.wisearchdepth = wi_searchdepth;
45334539
new_save_storyobj.wiinsertlocation = wi_insertlocation;
4540+
new_save_storyobj.logitbiasdict = JSON.parse(JSON.stringify(logitbiasdict));
45344541

45354542
if (export_settings) {
45364543
new_save_storyobj.savedsettings = JSON.parse(JSON.stringify(localsettings));
@@ -4746,6 +4753,9 @@ Current version: 101
47464753
if (storyobj.anotestr) {
47474754
anote_strength = storyobj.anotestr;
47484755
}
4756+
if (storyobj.logitbiasdict) {
4757+
logitbiasdict = storyobj.logitbiasdict;
4758+
}
47494759
if (storyobj.wisearchdepth) {
47504760
wi_searchdepth = storyobj.wisearchdepth;
47514761
}
@@ -5885,6 +5895,27 @@ Current version: 101
58855895
},false,true);
58865896
}
58875897

5898+
var pendinglogitbias = {};
5899+
function set_logit_bias()
5900+
{
5901+
inputBox("Enter OpenAI-formatted logit bias dictionary. Each key is the integer token IDs and their values are the biases (-100.0 to 100.0)<br><a href='https://platform.openai.com/docs/api-reference/chat/create#chat-create-logit_bias' class='color_blueurl'>Input is a JSON object, reference here.</a><br>Leave blank to disable.<br>","Set Logit Biases",JSON.stringify(pendinglogitbias),"Enter JSON Object",()=>{
5902+
let userinput = getInputBoxValue().trim();
5903+
if(userinput=="")
5904+
{
5905+
pendinglogitbias = {};
5906+
}
5907+
else
5908+
{
5909+
try {
5910+
pendinglogitbias = JSON.parse(userinput);
5911+
} catch (e) {
5912+
msgbox("Your logit bias JSON dictionary was not correctly formatted!");
5913+
}
5914+
}
5915+
5916+
},true,true);
5917+
}
5918+
58885919
var msgboxOnDone = hide_msgbox;
58895920
function hide_msgbox() {
58905921
//hide msgbox ONLY
@@ -7660,6 +7691,7 @@ Current version: 101
76607691
anote_strength = document.getElementById("anote_strength").value;
76617692
extrastopseq = document.getElementById("extrastopseq").value;
76627693
newlineaftermemory = (document.getElementById("newlineaftermemory").checked?true:false);
7694+
logitbiasdict = pendinglogitbias;
76637695
hide_popups();
76647696
render_gametext();
76657697
}
@@ -7714,20 +7746,6 @@ Current version: 101
77147746
submit_payload.params.sampler_seed = localsettings.sampler_seed;
77157747
}
77167748

7717-
if((custom_kobold_endpoint != "" && is_using_kcpp_with_mirostat()))
7718-
{
7719-
if(localsettings.miro_type>0)
7720-
{
7721-
submit_payload.params.mirostat = localsettings.miro_type;
7722-
submit_payload.params.mirostat_tau = localsettings.miro_tau;
7723-
submit_payload.params.mirostat_eta = localsettings.miro_eta;
7724-
}
7725-
7726-
//also supports min_p, in that it wont crash, so add it on. it will be ignored if not found
7727-
submit_payload.params.min_p = localsettings.min_p;
7728-
submit_payload.params.presence_penalty = localsettings.presence_penalty;
7729-
}
7730-
77317749
//v2 api specific fields
77327750
submit_payload.workers = selected_workers.map((m) => { return m.id });
77337751

@@ -7835,6 +7853,7 @@ Current version: 101
78357853
current_wi = [];
78367854
extrastopseq = "";
78377855
anote_strength = 320;
7856+
logitbiasdict = {};
78387857
wi_searchdepth = 0;
78397858
wi_insertlocation = 0;
78407859
current_anotetemplate = "[Author's note: <|>]";
@@ -8581,20 +8600,6 @@ Current version: 101
85818600
submit_payload.params.sampler_seed = localsettings.sampler_seed;
85828601
}
85838602

8584-
if((custom_kobold_endpoint != "" && is_using_kcpp_with_mirostat()))
8585-
{
8586-
if(localsettings.miro_type>0)
8587-
{
8588-
submit_payload.params.mirostat = localsettings.miro_type;
8589-
submit_payload.params.mirostat_tau = localsettings.miro_tau;
8590-
submit_payload.params.mirostat_eta = localsettings.miro_eta;
8591-
}
8592-
8593-
//also supports min_p, in that it wont crash, so add it on. it will be ignored if not found
8594-
submit_payload.params.min_p = localsettings.min_p;
8595-
submit_payload.params.presence_penalty = localsettings.presence_penalty;
8596-
}
8597-
85988603
if((custom_kobold_endpoint != "" && is_using_kcpp_with_grammar()))
85998604
{
86008605
if(localsettings.grammar && localsettings.grammar!="")
@@ -8682,6 +8687,26 @@ Current version: 101
86828687
{
86838688
console.log(submit_payload);
86848689

8690+
//preprocess to add extra fields
8691+
if((custom_kobold_endpoint != "" && is_using_kcpp_with_mirostat()))
8692+
{
8693+
if(localsettings.miro_type>0)
8694+
{
8695+
submit_payload.params.mirostat = localsettings.miro_type;
8696+
submit_payload.params.mirostat_tau = localsettings.miro_tau;
8697+
submit_payload.params.mirostat_eta = localsettings.miro_eta;
8698+
}
8699+
8700+
//also supports min_p, in that it wont crash, so add it on. it will be ignored if not found
8701+
submit_payload.params.min_p = localsettings.min_p;
8702+
}
8703+
//presence pen and logit bias for OAI and newer kcpp
8704+
if((custom_kobold_endpoint != "" && is_using_kcpp_with_mirostat()) || custom_oai_endpoint!="")
8705+
{
8706+
submit_payload.params.presence_penalty = localsettings.presence_penalty;
8707+
submit_payload.params.logit_bias = JSON.parse(JSON.stringify(logitbiasdict));
8708+
}
8709+
86858710
startTimeTaken(); //timestamp start request
86868711

86878712
if (is_using_custom_ep()) {
@@ -8736,8 +8761,14 @@ Current version: 101
87368761

87378762
let targetep = (custom_oai_endpoint + oai_submit_endpoint);
87388763

8739-
//original range between 1 and 3, scale to 0 and 2
8740-
let scaled_rep_pen = (submit_payload.params.rep_pen - 1.0);
8764+
let scaled_rep_pen = 0;
8765+
if(submit_payload.params.presence_penalty > 0)
8766+
{
8767+
scaled_rep_pen = submit_payload.params.presence_penalty;
8768+
}else{
8769+
//original range between 1 and 3, scale to 0 and 2
8770+
scaled_rep_pen = (submit_payload.params.rep_pen - 1.0);
8771+
}
87418772
//logit bias prevents <|endoftext|>
87428773
let oai_payload =
87438774
{
@@ -8747,6 +8778,10 @@ Current version: 101
87478778
"temperature": submit_payload.params.temperature,
87488779
"top_p": submit_payload.params.top_p,
87498780
}
8781+
if(submit_payload.params.logit_bias && JSON.stringify(submit_payload.params.logit_bias) != '{}')
8782+
{
8783+
oai_payload.logit_bias = submit_payload.params.logit_bias;
8784+
}
87508785

87518786
if (document.getElementById("useoaichatcompl").checked) {
87528787
targetep = (custom_oai_endpoint + oai_submit_endpoint_turbo);
@@ -8763,7 +8798,12 @@ Current version: 101
87638798
}
87648799
}
87658800
else {
8766-
oai_payload.logit_bias = { "50256": -100 };
8801+
if(oai_payload.logit_bias)
8802+
{
8803+
oai_payload.logit_bias["50256"] = -100;
8804+
}else{
8805+
oai_payload.logit_bias = { "50256": -100 };
8806+
}
87678807
oai_payload.prompt = submit_payload.prompt;
87688808
}
87698809

@@ -10760,6 +10800,7 @@ Current version: 101
1076010800
document.getElementById("anote_strength").value = anote_strength;
1076110801
document.getElementById("extrastopseq").value = extrastopseq;
1076210802
document.getElementById("newlineaftermemory").checked = (newlineaftermemory?true:false);
10803+
pendinglogitbias = logitbiasdict;
1076310804
if(custom_kobold_endpoint!="" || !is_using_custom_ep() )
1076410805
{
1076510806
document.getElementById("noextrastopseq").classList.add("hidden");
@@ -12612,8 +12653,8 @@ Current version: 101
1261212653
<div class="justifyleft settinglabel">Extra Stopping Sequences <span class="helpicon">?<span
1261312654
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>
1261412655
<div class="color_red hidden" id="noextrastopseq">Stop Sequences may be unavailable.</div>
12615-
<input class="form-control" type="text" placeholder="None" value="" id="extrastopseq">
12616-
12656+
<input class="form-control stopseqbox" type="text" placeholder="None" value="" id="extrastopseq">
12657+
<button type="button" class="btn btn-primary" style="width:104px;padding:6px 6px;margin-bottom: 4px;" id="btnlogitbias" onclick="set_logit_bias()">Logit Biases</button>
1261712658
<br>
1261812659
<div class="popupfooter">
1261912660
<button type="button" class="btn btn-primary" onclick="confirm_memory()">OK</button>

0 commit comments

Comments
 (0)