mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-11 17:44:38 +00:00
fixed bad handling for malformed requests
This commit is contained in:
parent
cfbe8cffbd
commit
010b2a5a71
2 changed files with 88 additions and 38 deletions
108
klite.embd
108
klite.embd
|
@ -7,7 +7,7 @@ Just copy this single static HTML file anywhere and open it in a browser, or fro
|
||||||
Please go to https://github.com/LostRuins/lite.koboldai.net for updates on Kobold Lite.
|
Please go to https://github.com/LostRuins/lite.koboldai.net for updates on Kobold Lite.
|
||||||
If you are submitting a pull request for Lite, PLEASE use the above repo, not the KoboldCpp one.
|
If you are submitting a pull request for Lite, PLEASE use the above repo, not the KoboldCpp one.
|
||||||
Kobold Lite is under the AGPL v3.0 License unless otherwise exempted. Please do not remove this line.
|
Kobold Lite is under the AGPL v3.0 License unless otherwise exempted. Please do not remove this line.
|
||||||
Current version: 132
|
Current version: 133
|
||||||
-Concedo
|
-Concedo
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@ -5356,7 +5356,8 @@ Current version: 132
|
||||||
"comment": itm.comment,
|
"comment": itm.comment,
|
||||||
"folder": null,
|
"folder": null,
|
||||||
"selective": itm.selective,
|
"selective": itm.selective,
|
||||||
"constant": itm.constant
|
"constant": itm.constant,
|
||||||
|
"probability":100
|
||||||
};
|
};
|
||||||
current_wi.push(nwi);
|
current_wi.push(nwi);
|
||||||
}
|
}
|
||||||
|
@ -5495,7 +5496,8 @@ Current version: 132
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"folder": null,
|
"folder": null,
|
||||||
"selective": false,
|
"selective": false,
|
||||||
"constant": false
|
"constant": false,
|
||||||
|
"probability":100
|
||||||
};
|
};
|
||||||
loadedwi.push(nwi);
|
loadedwi.push(nwi);
|
||||||
}
|
}
|
||||||
|
@ -5524,7 +5526,8 @@ Current version: 132
|
||||||
"comment": itm.comment,
|
"comment": itm.comment,
|
||||||
"folder": null,
|
"folder": null,
|
||||||
"selective": itm.selective,
|
"selective": itm.selective,
|
||||||
"constant": itm.constant
|
"constant": itm.constant,
|
||||||
|
"probability":100
|
||||||
};
|
};
|
||||||
loadedwi.push(nwi);
|
loadedwi.push(nwi);
|
||||||
}
|
}
|
||||||
|
@ -5660,7 +5663,8 @@ Current version: 132
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"folder": null,
|
"folder": null,
|
||||||
"selective": false,
|
"selective": false,
|
||||||
"constant": false
|
"constant": false,
|
||||||
|
"probability":100
|
||||||
};
|
};
|
||||||
loadedwi.push(nwi);
|
loadedwi.push(nwi);
|
||||||
}
|
}
|
||||||
|
@ -5718,7 +5722,8 @@ Current version: 132
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"folder": null,
|
"folder": null,
|
||||||
"selective": false,
|
"selective": false,
|
||||||
"constant": false
|
"constant": false,
|
||||||
|
"probability":100
|
||||||
};
|
};
|
||||||
temp_scenario.worldinfo.push(nwi);
|
temp_scenario.worldinfo.push(nwi);
|
||||||
}
|
}
|
||||||
|
@ -9992,42 +9997,63 @@ Current version: 132
|
||||||
for (var x = 0; x < current_wi.length; ++x) {
|
for (var x = 0; x < current_wi.length; ++x) {
|
||||||
let wi = current_wi[x];
|
let wi = current_wi[x];
|
||||||
|
|
||||||
|
let shoulduse = false;
|
||||||
|
|
||||||
//see if this is a valid wi entry
|
//see if this is a valid wi entry
|
||||||
if (wi.key == null || wi.key == "") {
|
if (wi.content == null || wi.content == "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//selective, but bad secondary key. treat as only 1 key
|
|
||||||
let invalidseckey = (wi.selective && (wi.keysecondary == "" || wi.keysecondary == null));
|
|
||||||
|
|
||||||
let wiks = wi.key.split(",");
|
|
||||||
|
|
||||||
let shoulduse = false;
|
|
||||||
if (wi.constant) {
|
if (wi.constant) {
|
||||||
shoulduse = true;
|
shoulduse = true;
|
||||||
}
|
}
|
||||||
else if (!wi.selective || invalidseckey) {
|
else
|
||||||
if (localsettings.case_sensitive_wi) {
|
{
|
||||||
shoulduse = wiks.some(k => wimatch_context.includes(k.trim()));
|
//see if this is a valid wi entry
|
||||||
} else {
|
if (wi.key == null || wi.key == "") {
|
||||||
shoulduse = wiks.some(k => wimatch_context.includes(k.trim().toLowerCase()));
|
continue;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let wiks2 = wi.keysecondary.split(",");
|
|
||||||
if (localsettings.case_sensitive_wi) {
|
|
||||||
let t1 = wiks.some(k => wimatch_context.includes(k.trim()));
|
|
||||||
let t2 = wiks2.some(k => wimatch_context.includes(k.trim()));
|
|
||||||
shoulduse = (t1 && t2);
|
|
||||||
} else {
|
|
||||||
let t1 = wiks.some(k => wimatch_context.includes(k.trim().toLowerCase()));
|
|
||||||
let t2 = wiks2.some(k => wimatch_context.includes(k.trim().toLowerCase()));
|
|
||||||
shoulduse = (t1 && t2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//selective, but bad secondary key. treat as only 1 key
|
||||||
|
let invalidseckey = (wi.selective && (wi.keysecondary == "" || wi.keysecondary == null));
|
||||||
|
|
||||||
|
let wiks = wi.key.split(",");
|
||||||
|
|
||||||
|
if (!wi.selective || invalidseckey) {
|
||||||
|
if (localsettings.case_sensitive_wi) {
|
||||||
|
shoulduse = wiks.some(k => wimatch_context.includes(k.trim()));
|
||||||
|
} else {
|
||||||
|
shoulduse = wiks.some(k => wimatch_context.includes(k.trim().toLowerCase()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let wiks2 = wi.keysecondary.split(",");
|
||||||
|
if (localsettings.case_sensitive_wi) {
|
||||||
|
let t1 = wiks.some(k => wimatch_context.includes(k.trim()));
|
||||||
|
let t2 = wiks2.some(k => wimatch_context.includes(k.trim()));
|
||||||
|
shoulduse = (t1 && t2);
|
||||||
|
} else {
|
||||||
|
let t1 = wiks.some(k => wimatch_context.includes(k.trim().toLowerCase()));
|
||||||
|
let t2 = wiks2.some(k => wimatch_context.includes(k.trim().toLowerCase()));
|
||||||
|
shoulduse = (t1 && t2);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shoulduse) {
|
if (shoulduse) {
|
||||||
wistr += wi.content + "\n";
|
//check if randomness less than 100%
|
||||||
|
if(wi.probability && wi.probability<100)
|
||||||
|
{
|
||||||
|
let roll = Math.floor(Math.random() * 100) + 1;
|
||||||
|
if(roll>=wi.probability)
|
||||||
|
{
|
||||||
|
wistr += wi.content + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//always insert
|
||||||
|
wistr += wi.content + "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13112,7 +13138,8 @@ Current version: 132
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"folder": null,
|
"folder": null,
|
||||||
"selective": false,
|
"selective": false,
|
||||||
"constant": false
|
"constant": false,
|
||||||
|
"probability":100
|
||||||
};
|
};
|
||||||
current_wi.push(ne);
|
current_wi.push(ne);
|
||||||
update_wi();
|
update_wi();
|
||||||
|
@ -13123,6 +13150,8 @@ Current version: 132
|
||||||
current_wi[i].key = document.getElementById("wikey" + i).value;
|
current_wi[i].key = document.getElementById("wikey" + i).value;
|
||||||
current_wi[i].keysecondary = document.getElementById("wikeysec" + i).value;
|
current_wi[i].keysecondary = document.getElementById("wikeysec" + i).value;
|
||||||
current_wi[i].content = document.getElementById("wival" + i).value;
|
current_wi[i].content = document.getElementById("wival" + i).value;
|
||||||
|
let prb = document.getElementById("wirng" + i).value;
|
||||||
|
current_wi[i].probability = (prb?prb:100);
|
||||||
}
|
}
|
||||||
localsettings.case_sensitive_wi = (document.getElementById("case_sensitive_wi").checked?true:false);
|
localsettings.case_sensitive_wi = (document.getElementById("case_sensitive_wi").checked?true:false);
|
||||||
wi_searchdepth = document.getElementById("wi_searchdepth").value;
|
wi_searchdepth = document.getElementById("wi_searchdepth").value;
|
||||||
|
@ -13150,12 +13179,13 @@ Current version: 132
|
||||||
|
|
||||||
let wilist = document.getElementById("wilist");
|
let wilist = document.getElementById("wilist");
|
||||||
let qsval = document.getElementById("wiquicksearch").value;
|
let qsval = document.getElementById("wiquicksearch").value;
|
||||||
selectionhtml = `<table style="border-collapse: separate; border-spacing: 1.5pt;">`;
|
let selectionhtml = `<table style="border-collapse: separate; border-spacing: 1.5pt;">`;
|
||||||
for (var i = 0; i < current_wi.length; ++i) {
|
for (var i = 0; i < current_wi.length; ++i) {
|
||||||
var curr = current_wi[i];
|
var curr = current_wi[i];
|
||||||
var winame = escapeHtml(curr.key);
|
var winame = escapeHtml(curr.key);
|
||||||
var witxt = escapeHtml(curr.content);
|
var witxt = escapeHtml(curr.content);
|
||||||
var wisec = curr.keysecondary;
|
var wisec = curr.keysecondary;
|
||||||
|
var wirngval = (curr.probability?curr.probability:100);
|
||||||
|
|
||||||
var ishidden = false;
|
var ishidden = false;
|
||||||
if(qsval!="" && !winame.toLowerCase().includes(qsval.toLowerCase()) && !witxt.toLowerCase().includes(qsval.toLowerCase()))
|
if(qsval!="" && !winame.toLowerCase().includes(qsval.toLowerCase()) && !witxt.toLowerCase().includes(qsval.toLowerCase()))
|
||||||
|
@ -13163,6 +13193,8 @@ Current version: 132
|
||||||
ishidden = true;
|
ishidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let probarr = [100,90,75,50,25,10,5,1];
|
||||||
|
|
||||||
selectionhtml += `<tr class='`+ (ishidden?"hidden":"") +`' id="wirow` + i + `"><td class="col-8" style="font-size: 10px;">` +
|
selectionhtml += `<tr class='`+ (ishidden?"hidden":"") +`' id="wirow` + i + `"><td class="col-8" style="font-size: 10px;">` +
|
||||||
`<button type="button" class="btn btn-danger widelbtn" id="widel` + i + `" onclick="return del_wi(` + i + `)">X</button></td>` +
|
`<button type="button" class="btn btn-danger widelbtn" id="widel` + i + `" onclick="return del_wi(` + i + `)">X</button></td>` +
|
||||||
`<td class="col-6 wiinputkeycol">
|
`<td class="col-6 wiinputkeycol">
|
||||||
|
@ -13170,11 +13202,19 @@ Current version: 132
|
||||||
<input class="form-control wiinputkey `+ (curr.selective ? `` : `hidden`) + `" id="wikeysec` + i + `" placeholder="Sec. Key(s)" value="` + wisec + `">` + `</td>
|
<input class="form-control wiinputkey `+ (curr.selective ? `` : `hidden`) + `" id="wikeysec` + i + `" placeholder="Sec. Key(s)" value="` + wisec + `">` + `</td>
|
||||||
<td class="col-10 wiinputvalcol">
|
<td class="col-10 wiinputvalcol">
|
||||||
<textarea class="form-control wiinputval" style="line-height:1.1" id="wival`+ i + `" placeholder="What To Remember" rows="3">` + witxt + `</textarea>
|
<textarea class="form-control wiinputval" style="line-height:1.1" id="wival`+ i + `" placeholder="What To Remember" rows="3">` + witxt + `</textarea>
|
||||||
</td>`+
|
</td>
|
||||||
`
|
|
||||||
<td>
|
<td>
|
||||||
<a id="wiskt`+ i + `" href="#" class=` + (curr.selective ? "witoggleron" : "witoggleroff") + ` title="Toggle Selective Key mode (if enabled, this world info entry will be included in memory only if at least one PRIMARY KEY and at least one SECONDARY KEY are both present in the story)" onclick="return toggle_wi_sk(` + i + `)">📑</a>
|
<a id="wiskt`+ i + `" href="#" class=` + (curr.selective ? "witoggleron" : "witoggleroff") + ` title="Toggle Selective Key mode (if enabled, this world info entry will be included in memory only if at least one PRIMARY KEY and at least one SECONDARY KEY are both present in the story)" onclick="return toggle_wi_sk(` + i + `)">📑</a>
|
||||||
<a id="wickt`+ i + `" href="#" class=` + (curr.constant ? "witoggleron" : "witoggleroff") + ` title="Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)" onclick="return toggle_wi_ck(` + i + `)">📌</a>
|
<a id="wickt`+ i + `" href="#" class=` + (curr.constant ? "witoggleron" : "witoggleroff") + ` title="Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)" onclick="return toggle_wi_ck(` + i + `)">📌</a>
|
||||||
|
<select id="wirng`+i+`" style="padding:1px; height:auto; width: 30px; appearance: none; font-size: 7pt;" class="form-control" title="Chance to trigger if allowed">`;
|
||||||
|
|
||||||
|
let opts = "";
|
||||||
|
for(let n=0;n<probarr.length;++n)
|
||||||
|
{
|
||||||
|
opts += `<option value="`+probarr[n]+`" `+(probarr[n]==wirngval?"selected":"")+`>`+probarr[n]+`%</option>`;
|
||||||
|
}
|
||||||
|
selectionhtml += opts +`
|
||||||
|
</select>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
|
|
18
koboldcpp.py
18
koboldcpp.py
|
@ -622,7 +622,7 @@ maxhordelen = 256
|
||||||
modelbusy = threading.Lock()
|
modelbusy = threading.Lock()
|
||||||
requestsinqueue = 0
|
requestsinqueue = 0
|
||||||
defaultport = 5001
|
defaultport = 5001
|
||||||
KcppVersion = "1.62.2"
|
KcppVersion = "1.63"
|
||||||
showdebug = True
|
showdebug = True
|
||||||
showsamplerwarning = True
|
showsamplerwarning = True
|
||||||
showmaxctxwarning = True
|
showmaxctxwarning = True
|
||||||
|
@ -1155,8 +1155,12 @@ Enter Prompt:<br>
|
||||||
|
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
global modelbusy, requestsinqueue, currentusergenkey, totalgens, pendingabortkey
|
global modelbusy, requestsinqueue, currentusergenkey, totalgens, pendingabortkey
|
||||||
content_length = int(self.headers['content-length'])
|
contlenstr = self.headers['content-length']
|
||||||
body = self.rfile.read(content_length)
|
content_length = 0
|
||||||
|
body = None
|
||||||
|
if contlenstr:
|
||||||
|
content_length = int(contlenstr)
|
||||||
|
body = self.rfile.read(content_length)
|
||||||
self.path = self.path.rstrip('/')
|
self.path = self.path.rstrip('/')
|
||||||
response_body = None
|
response_body = None
|
||||||
response_code = 200
|
response_code = 200
|
||||||
|
@ -1293,7 +1297,13 @@ Enter Prompt:<br>
|
||||||
genparams = json.loads(body)
|
genparams = json.loads(body)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
utfprint("Body Err: " + str(body))
|
utfprint("Body Err: " + str(body))
|
||||||
return self.send_response(503)
|
self.send_response(500)
|
||||||
|
self.end_headers(content_type='application/json')
|
||||||
|
self.wfile.write(json.dumps({"detail": {
|
||||||
|
"msg": "Error parsing input.",
|
||||||
|
"type": "bad_input",
|
||||||
|
}}).encode())
|
||||||
|
return
|
||||||
|
|
||||||
is_quiet = args.quiet
|
is_quiet = args.quiet
|
||||||
if (args.debugmode != -1 and not is_quiet) or args.debugmode >= 1:
|
if (args.debugmode != -1 and not is_quiet) or args.debugmode >= 1:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue