Skip to content

Commit 1eb6d25

Browse files
committed
truncate middle instead of end for long strings
1 parent f841b29 commit 1eb6d25

File tree

2 files changed

+105
-36
lines changed

2 files changed

+105
-36
lines changed

klite.embd

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
1212
-->
1313

1414
<script>
15-
const LITEVER = 240;
15+
const LITEVER = 241;
1616
const urlParams = new URLSearchParams(window.location.search);
1717
var localflag = urlParams.get('local'); //this will be replaced automatically in embedded kcpp
1818
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@@ -3206,6 +3206,7 @@ Current version indicated by LITEVER below.
32063206
saved_xtts_url: default_xtts_base,
32073207
saved_alltalk_url: default_alltalk_base,
32083208
prev_custom_endpoint_type: 0, //show a reconnect box to custom endpoint if needed. 0 is horde, otherwise its dropdown value+1
3209+
prev_custom_endpoint_model: "", //we may not be able to match, but set it if we do
32093210
generate_images_mode: (localflag?0:1), //0=off, 1=horde, 2=a1111, 3=dalle, 4=comfy, 5=pollinations
32103211

32113212
autoscroll: true, //automatically scroll to bottom on render
@@ -3251,7 +3252,7 @@ Current version indicated by LITEVER below.
32513252
image_styles: "",
32523253
image_negprompt: "",
32533254
grammar:"",
3254-
tokenstreammode: (localflag?2:0), //0=off,1=pollstream,2=sse
3255+
tokenstreammode: 2, //0=off,1=pollstream,2=sse
32553256
generate_images_model: "stable_diffusion", //"" is disabled and "*" is all, anything else is the model name pulled from stable horde
32563257
img_gen_from_instruct: true,
32573258
img_autogen: false,
@@ -4045,10 +4046,22 @@ Current version indicated by LITEVER below.
40454046

40464047
//offer to reconnect
40474048
let pending_eptype = localsettings.prev_custom_endpoint_type;
4049+
let pending_custmodel = localsettings.prev_custom_endpoint_model;
40484050
if(!localflag && pending_eptype>0)
40494051
{
40504052
msgboxYesNo("Reconnect to previous custom endpoint?","Custom Endpoint Reconnect",()=>{
40514053
document.getElementById("customapidropdown").value = (pending_eptype).toString();
4054+
if(pending_custmodel)
4055+
{
4056+
let dropdown = get_custom_ep_model_dropdown();
4057+
if(dropdown)
4058+
{
4059+
const hasValue = Array.from(dropdown.options).some(option => option.value === pending_custmodel);
4060+
if (hasValue) {
4061+
dropdown.value = pending_custmodel;
4062+
}
4063+
}
4064+
}
40524065
display_endpoint_container();
40534066
},null);
40544067
}
@@ -4134,12 +4147,6 @@ Current version indicated by LITEVER below.
41344147
});
41354148
}
41364149

4137-
const tokenstreaming = urlParams.get('streaming');
4138-
if(tokenstreaming)
4139-
{
4140-
localsettings.tokenstreammode = 1;
4141-
}
4142-
41434150
//toggle genimg btn
41444151
update_genimg_button_visiblility();
41454152
update_websearch_button_visibility();
@@ -5537,6 +5544,14 @@ Current version indicated by LITEVER below.
55375544
return input;
55385545
};
55395546
const formatMarkdown = (md) => {
5547+
let append_spcetg = false;
5548+
if(md.trim().startsWith("%SpcEtg%")) //this can cause issues matching start of response, so we note it down and remove it first
5549+
{
5550+
let idxof = md.indexOf("%SpcEtg%");
5551+
md = md.substring(idxof+8);
5552+
append_spcetg = true;
5553+
}
5554+
55405555
md = md.replace(/^###### (.*?)\s*#*$/gm, "<h6>$1</h6>")
55415556
.replace(/^##### (.*?)\s*#*$/gm, "<h5>$1</h5>")
55425557
.replace(/^#### (.*?)\s*#*$/gm, "<h4>$1</h4>")
@@ -5593,6 +5608,11 @@ Current version indicated by LITEVER below.
55935608
.replace(/^((?:\|[^|\r\n]*[^|\r\n\s]\s*)+\|(?:\r?\n|\r|))+/gm,
55945609
(matchedTable) => convertMarkdownTableToHtml(matchedTable))
55955610
.replace(/ \n/g, "\n<br/>");
5611+
if(append_spcetg)
5612+
{
5613+
append_spcetg = false;
5614+
md = `%SpcEtg%${md}`;
5615+
}
55965616
md = replaceTabbedCodeblocks(md);
55975617
md = md.replace(/<\/code\><\/pre\>\n<pre\><code\>/g, "\n");
55985618
if(renderLatex)
@@ -6182,7 +6202,7 @@ Current version indicated by LITEVER below.
61826202
height: req_payload.params.height,
61836203
nologo: true,
61846204
private: true,
6185-
referrer: "KoboldAiLite"
6205+
referrer: "koboldai"
61866206
});
61876207

61886208
let gen_endpoint = `${pollinations_img_endpoint}/${encodeURIComponent(prompt)}?${pollinations_params.toString()}`;
@@ -9223,13 +9243,25 @@ Current version indicated by LITEVER below.
92239243
}
92249244
}
92259245

9226-
function get_oai_model_dropdown()
9246+
function get_custom_ep_model_dropdown(ep_id=null) //if desired id not provided, use dynamic val
92279247
{
9228-
let ddval = document.getElementById("customapidropdown").value;
9248+
let ddval = (ep_id?ep_id.toString():document.getElementById("customapidropdown").value);
92299249
switch(ddval)
92309250
{
9251+
case "0": //horde
9252+
return document.getElementById("custom_oai_model"); //just return oai
9253+
case "1": //kai
9254+
return document.getElementById("custom_oai_model"); //just return oai
9255+
case "2":
9256+
return document.getElementById("custom_oai_model");
92319257
case "3":
92329258
return document.getElementById("custom_openrouter_model");
9259+
case "4":
9260+
return document.getElementById("custom_claude_model");
9261+
case "5":
9262+
return document.getElementById("custom_gemini_model");
9263+
case "6":
9264+
return document.getElementById("custom_cohere_model");
92339265
case "7":
92349266
return document.getElementById("custom_mistralai_model");
92359267
case "8":
@@ -9239,7 +9271,7 @@ Current version indicated by LITEVER below.
92399271
case "10":
92409272
return document.getElementById("custom_pollinations_model");
92419273
default:
9242-
return document.getElementById("custom_oai_model");
9274+
return document.getElementById("custom_oai_model"); //just return oai
92439275
}
92449276
}
92459277
function ep_should_always_use_chat_completions()
@@ -9252,7 +9284,7 @@ Current version indicated by LITEVER below.
92529284
{
92539285
inputBox("Enter custom model name","Custom Model Name",localsettings.saved_oai_custommodel,"", ()=>{
92549286
let coai = getInputBoxValue().trim();
9255-
let dropdown = get_oai_model_dropdown();
9287+
let dropdown = get_custom_ep_model_dropdown();
92569288
var mdlopt = dropdown.querySelector('option.custom_model_option');
92579289
if(coai!="")
92589290
{
@@ -9266,7 +9298,7 @@ Current version indicated by LITEVER below.
92669298
}
92679299
function oai_model_change(autotoggle_check = false)
92689300
{
9269-
let dropdown = get_oai_model_dropdown();
9301+
let dropdown = get_custom_ep_model_dropdown();
92709302
let non_completions = (dropdown.value.includes("davinci-002") || dropdown.value.includes("text-davinci-003") || dropdown.value.includes("text-davinci-002")
92719303
|| dropdown.value.includes("text-davinci-001") || dropdown.value.includes("gpt-3.5-turbo-instruct") || dropdown.value == "davinci");
92729304
if(autotoggle_check)
@@ -9428,7 +9460,7 @@ Current version indicated by LITEVER below.
94289460
}
94299461

94309462
let isOpenrouter = (document.getElementById("customapidropdown").value==3);
9431-
let dropdown = get_oai_model_dropdown();
9463+
let dropdown = get_custom_ep_model_dropdown();
94329464
fetch((desired_oai_ep + oai_models_endpoint), {
94339465
method: 'GET',
94349466
headers: oaiheaders,
@@ -10148,7 +10180,7 @@ Current version indicated by LITEVER below.
1014810180
}
1014910181
localsettings.saved_oai_role = document.getElementById("oairoledropdown").value;
1015010182
localsettings.saved_oai_jailbreak2 = document.getElementById("jailbreakprompttext2").value;
10151-
let dropdown = get_oai_model_dropdown();
10183+
let dropdown = get_custom_ep_model_dropdown();
1015210184
custom_oai_model = dropdown.value.trim();
1015310185
localsettings.saved_oai_custommodel = custom_oai_model;
1015410186
selected_models = [{ "performance": 100.0, "queued": 0.0, "eta": 0, "name": custom_oai_model, "count": 1 }];
@@ -11437,13 +11469,13 @@ Current version indicated by LITEVER below.
1143711469
document.getElementById("voice_typing_mode").disabled = !is_using_kcpp_with_whisper();
1143811470
document.getElementById("grammar_retain_state").disabled = document.getElementById("setgrammar").disabled;
1143911471

11440-
if(custom_kobold_endpoint!="")
11472+
if(custom_kobold_endpoint=="" && custom_oai_key=="" && custom_gemini_key=="")
1144111473
{
11442-
document.getElementById("tokenstreaminglabel").classList.remove("color_red");
11474+
document.getElementById("tokenstreaminglabel").classList.add("color_red");
1144311475
}
1144411476
else
1144511477
{
11446-
document.getElementById("tokenstreaminglabel").classList.add("color_red");
11478+
document.getElementById("tokenstreaminglabel").classList.remove("color_red");
1144711479
}
1144811480
document.getElementById("generate_images_model").value = localsettings.generate_images_model;
1144911481
if(document.getElementById("generate_images_mode").value == 0 || document.getElementById("generate_images_mode").value != localsettings.generate_images_mode) {
@@ -13771,7 +13803,7 @@ Current version indicated by LITEVER below.
1377113803
model:"openai-audio",
1377213804
voice:"nova",
1377313805
private: true,
13774-
referrer: "KoboldAiLite"
13806+
referrer: "koboldai"
1377513807
});
1377613808
const speechprompt = `Please narrate the following text:\n\n${text}`;
1377713809

@@ -14186,7 +14218,7 @@ Current version indicated by LITEVER below.
1418614218
{
1418714219
let newgenlc = newgen.toLowerCase().trim();
1418814220
if (newgenlc.startsWith("draw ") ||
14189-
newgenlc.match(/\b(?:draw (?:a|an)\b)|(?:draw me (?:a|an)\b)|(?:(?:draw|show me|generate|create|make|illustrate|visualize|produce|give me)(?:\s\w+){0,4}\s(?:image|picture|drawing|photo))/))
14221+
newgenlc.match(/\b(?:draw (?:a|an)\b)|(?:draw me (?:a|an)\b)|(?:(?:draw|show me|generate|create|make|illustrate|visualize|produce|give me)(?:\s\w+){0,4}\s(?:image\b|picture\b|drawing\b|photo))/))
1419014222
{
1419114223
img_gen_trigger_prompt = newgen;
1419214224
doNotGenerate = true;
@@ -15321,10 +15353,10 @@ Current version indicated by LITEVER below.
1532115353
{
1532215354
targetep = pollinations_text_endpoint;
1532315355
oai_payload.private = true;
15324-
oai_payload.referrer = "KoboldAiLite";
15356+
oai_payload.referrer = "koboldai";
1532515357
}
1532615358

15327-
if(is_browser_supports_sse() && document.getElementById("oaistreaming").checked)
15359+
if(is_browser_supports_sse() && localsettings.tokenstreammode!=0)
1532815360
{
1532915361
oai_payload.stream = true;
1533015362
oai_api_stream_sse(targetep,oai_payload,oaiheaders);
@@ -15622,7 +15654,7 @@ Current version indicated by LITEVER below.
1562215654
last_response_obj = null;
1562315655

1562415656
let geminiheaders = { 'Content-Type': 'application/json' };
15625-
if(is_browser_supports_sse() && document.getElementById("geministreaming").checked)
15657+
if(is_browser_supports_sse() && localsettings.tokenstreammode!=0)
1562615658
{
1562715659
let targetep = default_gemini_base + mdlname + default_gemini_stream_suffix + custom_gemini_key;
1562815660
oai_api_stream_sse(targetep,payload,geminiheaders);
@@ -19617,6 +19649,7 @@ Current version indicated by LITEVER below.
1961719649
function update_prev_custom_endpoint_type()
1961819650
{
1961919651
localsettings.prev_custom_endpoint_type = 0;
19652+
localsettings.prev_custom_endpoint_model = "";
1962019653
if (custom_kobold_endpoint != "") {
1962119654
localsettings.prev_custom_endpoint_type = 1;
1962219655
}
@@ -19653,6 +19686,14 @@ Current version indicated by LITEVER below.
1965319686
localsettings.prev_custom_endpoint_type = 6;
1965419687
}
1965519688

19689+
if(localsettings.prev_custom_endpoint_type!=0 && localsettings.prev_custom_endpoint_type!=1)
19690+
{
19691+
let dropdown = get_custom_ep_model_dropdown(localsettings.prev_custom_endpoint_type);
19692+
if(dropdown && dropdown.value)
19693+
{
19694+
localsettings.prev_custom_endpoint_model = dropdown.value;
19695+
}
19696+
}
1965619697
}
1965719698

1965819699
function autosave() {
@@ -23169,7 +23210,7 @@ Current version indicated by LITEVER below.
2316923210
<div id="oaicustom" class="menutext hidden">
2317023211
<span id="oaidesc">
2317123212
Entering your OpenAI API key will allow you to use KoboldAI Lite with their API.<br><br>
23172-
Note that KoboldAI Lite takes no responsibility for your usage or consequences of this feature. Your API key is used directly with the OpenAI API and is not transmitted to us.<br>Only Temperature, Top-P and Repetition Penalty samplers are used.<br><br>
23213+
Note that KoboldAI Lite takes no responsibility for your usage or consequences of this feature. Your API key is used directly with the OpenAI API and is not transmitted to us. Note that connecting will reset any custom DALL-E based or custom OpenAI based TTS endpoint urls to this new address.<br>Only Temperature, Top-P and Repetition Penalty samplers are used.<br><br>
2317323214
<span class="color_green" style="font-weight: bold;">Please input OpenAI API URL and Key.</span><br><br>
2317423215
</span>
2317523216
<span id="openrouterdesc" class="hidden">
@@ -23209,9 +23250,19 @@ Current version indicated by LITEVER below.
2320923250
<option value="gpt-4">gpt-4</option>
2321023251
<option value="gpt-4-turbo">gpt-4-turbo</option>
2321123252
<option value="gpt-4o">gpt-4o</option>
23253+
<option value="gpt-4o-mini">gpt-4o-mini</option>
2321223254
<option value="gpt-4-32k">gpt-4-32k</option>
23255+
<option value="gpt-4.1">gpt-4.1</option>
23256+
<option value="gpt-4.1-mini">gpt-4.1-mini</option>
23257+
<option value="gpt-4.1-nano">gpt-4.1-nano</option>
23258+
<option value="gpt-4.5-preview">gpt-4.5-preview</option>
23259+
<option value="chatgpt-4o-latest">chatgpt-4o-latest</option>
2321323260
<option value="o1-mini">o1-mini</option>
23261+
<option value="o1">o1</option>
2321423262
<option value="o1-preview">o1-preview</option>
23263+
<option value="o3-mini">o3-mini</option>
23264+
<option value="o3">o3</option>
23265+
<option value="o4-mini">o4-mini</option>
2321523266
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
2321623267
</select>
2321723268
<select title="OpenRouter AI Model Selection" style="padding:4px;display:inline;width:calc(100% - 220px)" class="form-control hidden" id="custom_openrouter_model" onchange="oai_model_change(true)">
@@ -23231,7 +23282,10 @@ Current version indicated by LITEVER below.
2323123282
<option value="mistral-tiny">mistral-tiny</option>
2323223283
<option value="mistral-small">mistral-small</option>
2323323284
<option value="mistral-medium-latest">mistral-medium-latest</option>
23285+
<option value="mistral-large-2407">mistral-large-2407</option>
2323423286
<option value="mistral-large-latest">mistral-large-latest</option>
23287+
<option value="ministral-3b-latest">ministral-3b-latest</option>
23288+
<option value="ministral-8b-latest">ministral-8b-latest</option>
2323523289
<option value="pixtral-12b-latest">pixtral-12b-latest</option>
2323623290
<option value="pixtral-large-latest">pixtral-large-latest</option>
2323723291
<option value="codestral-latest">codestral-latest</option>
@@ -23275,6 +23329,7 @@ Current version indicated by LITEVER below.
2327523329
<option value="rtist">rtist</option>
2327623330
<option value="searchgpt">searchgpt</option>
2327723331
<option value="unity">unity</option>
23332+
<option value="bidara">bidara</option>
2327823333
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
2327923334
</select>
2328023335
<button type="button" class="btn btn-primary" style="display:inline;width:105px;" id="oaifetchlist" onclick="oai_fetch_models()">Fetch List</button>
@@ -23286,8 +23341,6 @@ Current version indicated by LITEVER below.
2328623341
<div style="display:inline-flex">
2328723342
<div><input type="checkbox" id="oaiaddversion" title="Add Endpoint Version Number" onchange="" checked>
2328823343
<div class="box-label">Add Ver. Num</div></div>
23289-
<div><input type="checkbox" id="oaistreaming" title="Enable SSE Streaming" onchange="">
23290-
<div class="box-label">Streaming</div></div>
2329123344
<div><input type="checkbox" id="useoaichatcompl" title="Use ChatCompletions API" onchange="toggleoaichatcompl()">
2329223345
<div class="box-label">Chat-Completions API</div></div>
2329323346
<div><input type="checkbox" id="useoainonstandard" title="Send Non-Standard Fields">
@@ -23388,6 +23441,11 @@ Current version indicated by LITEVER below.
2338823441
<option value="gemini-2.0-flash">gemini-2.0-flash</option>
2338923442
<option value="gemini-2.0-flash-lite">gemini-2.0-flash-lite</option>
2339023443
<option value="gemini-2.0-pro-exp">gemini-2.0-pro-exp</option>
23444+
<option value="gemini-2.5-flash-preview-04-17">gemini-2.5-flash-preview-04-17</option>
23445+
<option value="gemini-2.5-pro-preview-05-06">gemini-2.5-pro-preview-05-06</option>
23446+
<option value="gemma-3-1b-it">gemma-3-1b-it</option>
23447+
<option value="gemma-3-4b-it">gemma-3-4b-it</option>
23448+
<option value="gemma-3-12b-it">gemma-3-12b-it</option>
2339123449
<option value="gemma-3-27b-it">gemma-3-27b-it</option>
2339223450
</select>
2339323451
<button type="button" class="btn btn-primary" style="display:inline;width:105px;" id="geminifetchlist" onclick="gemini_fetch_models()">Fetch List</button>
@@ -23423,15 +23481,12 @@ Current version indicated by LITEVER below.
2342323481
<input type="checkbox" title="Allow Gemini Thinking" id="usegeminithink" checked>
2342423482
<div class="box-label">Allow Thinking</div>
2342523483
</div>
23426-
<div><input type="checkbox" id="geministreaming" title="Enable SSE Streaming" onchange="">
23427-
<div class="box-label">Streaming</div>
23428-
</div>
2342923484
</div>
2343023485
</div>
2343123486
<div id="coherecustom" class="menutext hidden">
2343223487
Uses Cohere's models through their own API.<br><br>
2343323488
Note that KoboldAI Lite takes no responsibility for your usage or consequences of this feature. Your API key is used directly with the Cohere API and is not transmitted to us.<br><br>
23434-
<select title="Cohere AI Model Selection" style="padding:4px;" class="form-control" id="custom_cohere_model">
23489+
<select title="Cohere AI Model Selection" style="padding:4px;" class="form-control" id="custom_cohere_model">
2343523490
<option value="command" selected="selected">command</option>
2343623491
<option value="command-r">command-r</option>
2343723492
<option value="command-r-plus">command-r-plus</option>

0 commit comments

Comments
 (0)