update lite and sdui

This commit is contained in:
Concedo 2026-08-01 11:17:16 +08:00
parent 650a4f2eb8
commit 2f2ebefc35
2 changed files with 70 additions and 33 deletions

File diff suppressed because one or more lines are too long

View file

@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
-->
<head>
<script id="init-config">
const LITEVER = 340;
const LITEVER = 341;
const urlParams = new URLSearchParams(window.location.search);
var localflag = urlParams.get('local'); //this will be replaced automatically in embedded kcpp
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@ -4111,6 +4111,8 @@ Current version indicated by LITEVER below.
var poll_interval_multiplayer = 1000; //every 1s
var poll_interval_chunked_tts = 300;
var max_branches = 8;
var randomness_max_size = 500;
var randomness_allow_newlines = false;
var horde_base_url = "https://aihorde.net"
var horde_perf_endpoint = horde_base_url + "/api/v2/status/performance";
@ -6182,19 +6184,21 @@ Current version indicated by LITEVER below.
if (lowerinputtxt.includes("\{\{pick") || lowerinputtxt.includes("\{\{random") || lowerinputtxt.includes("\{\{roll"))
{
let stablereg = "";
let randomness_content = "[^}" + (randomness_allow_newlines ? "" : "\\n") + "]";
let randomness_range = "{1," + randomness_max_size + "}";
if(!isgametext)
{
inputtxt = inputtxt.replace(/\{\{roll\s?:?:?([^\}\n]{1,500})\}\}/gi, function (m,matchValue) {
inputtxt = inputtxt.replace(RegExp("\\{\\{roll\\s?:?:?(" + randomness_content + randomness_range + ")\\}\\}","gi"), function (m,matchValue) {
return dicenotation(matchValue, 0);
});
inputtxt = inputtxt.replace(/\{\{random\s?:?:?([^\}\n]{1,500})\}\}/gi, function (m,listString) {
inputtxt = inputtxt.replace(RegExp("\\{\\{random\\s?:?:?(" + randomness_content + randomness_range + ")\\}\\}","gi"), function (m,listString) {
return pickfromlist(listString,0);
});
stablereg = /\{\{(pick)\s?:?:?([^\}\n]{1,500})\}\}/gi;
stablereg = RegExp("\\{\\{(pick)\\s?:?:?(" + randomness_content + randomness_range + ")\\}\\}","gi");
}
else
{
stablereg = /\{\{(pick|random|roll)\s?:?:?([^\}\n]{1,500})\}\}/gi;
stablereg = RegExp("\\{\\{(pick|random|roll)\\s?:?:?(" + randomness_content + randomness_range + ")\\}\\}","gi");
}
let countmap = (persistent_countmap?persistent_countmap:new Map());
@ -13729,6 +13733,14 @@ Current version indicated by LITEVER below.
}
}
toggleoaichatcompl();
document.getElementById("model_cost").innerText = "";
if(cached_model_pricing[dropdown.value])
{
let data = cached_model_pricing[dropdown.value];
let price_input = (data.prompt * 1000000).toFixed(2);
let price_output = (data.completion * 1000000).toFixed(2);
document.getElementById("model_cost").innerText = `($${price_input} / $${price_output} per 1M)`;
}
}
function claude_fetch_models()
{
@ -13803,6 +13815,7 @@ Current version indicated by LITEVER below.
}
function update_oai_model_list(data, dropdown, epchoice)
{
cached_model_pricing = {};
var lastOption = dropdown.lastElementChild;
for (var i = dropdown.options.length - 1; i >= 0; i--) {
var option = dropdown.options[i];
@ -13813,6 +13826,10 @@ Current version indicated by LITEVER below.
for(var i = 0; i < data.data.length; i++) {
var opt = data.data[i];
sortedarr.push(opt.id);
if(opt.pricing)
{
cached_model_pricing[opt.id] = opt.pricing;
}
}
sortedarr.sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' }));
let pending_custmodel = (localsettings.prev_custom_endpoint_model_dict?(localsettings.prev_custom_endpoint_model_dict[epchoice] || ""):"");
@ -13923,6 +13940,7 @@ Current version indicated by LITEVER below.
}
let autofetch_attempt_dict = {};
let cached_model_pricing = {};
function try_fetch_oai_models_auto()
{
let targetep = document.getElementById("custom_oai_endpoint").value;
@ -17709,10 +17727,9 @@ Current version indicated by LITEVER below.
pending_response_id = "-1";
waiting_for_summarycall = 2;
let max_allowed_characters = Math.floor(localsettings.max_context_length * 3.0) - 100;
let truncated_context = recentCtx.substring(recentCtx.length - max_allowed_characters);
truncated_context = replace_placeholders(truncated_context);
let wst = (localsettings.websearch_template==""?default_websearch_template:localsettings.websearch_template);
let truncated_context = replace_placeholders(recentCtx);
truncated_context = substring_to_boundary(truncated_context, max_allowed_characters);
truncated_context += "\n\n" + wst.replaceAll('{{QUERY}}', search_query);
let submit_payload = {
@ -17785,14 +17802,15 @@ Current version indicated by LITEVER below.
}
truncated_context = end_trim_to_sentence(truncated_context,true);
truncated_context = truncated_context.substring(truncated_context.length - max_allowed_characters);
truncated_context = replace_placeholders(truncated_context);
truncated_context = substring_to_boundary(truncated_context, max_allowed_characters);
truncated_memory = truncate_memory(replace_placeholders(truncated_memory), max_mem_len, false);
let augmented_len = truncated_memory.length + truncated_context.length;
let excess_len = augmented_len - max_allowed_characters; //if > 0, then we exceeded context window
truncated_context = truncated_memory + truncated_context.substring(excess_len);
let long_story = (truncated_context.length>1800?true:false);
truncated_context += "\n### Instruction: Summarize the above text in a single paragraph of up to "+(long_story?"ten":"five")+" detailed sentences.\n### Response:";
truncated_context = replace_placeholders(truncated_context);
let submit_payload = {
"prompt": truncated_context,
"params": {
@ -20501,6 +20519,9 @@ Current version indicated by LITEVER below.
}
}
truncated_context = replace_placeholders(truncated_context,false,false,true);
truncated_context = substring_to_boundary(truncated_context, max_allowed_characters);
//we clip the memory if its too long, taking the last x chars (not the first)
//memory is allowed to be up to 0.8 times of ctx allowance, anote up to 0.6 times
let max_mem_len = Math.floor(max_allowed_characters*0.8);
@ -20523,7 +20544,7 @@ Current version indicated by LITEVER below.
{
memory_with_groupchat_context += (memory_with_groupchat_context.trim()!="" ? "\n" : "") + groupchat_context_memory;
}
let truncated_memory = truncate_memory(memory_with_groupchat_context, max_mem_len, true);
let truncated_memory = memory_with_groupchat_context;
if (truncated_memory != null && truncated_memory != "") {
if(newlineaftermemory)
{
@ -20715,9 +20736,7 @@ Current version indicated by LITEVER below.
wistr = substring_to_boundary(wistr, max_wi_len);
}
//we clip the authors note if its too long
let truncated_anote = current_anotetemplate.replace("<|>", current_anote);
truncated_anote = substring_to_boundary(truncated_anote, max_anote_len);
if (current_anote.length == 0) {
//if there's no authors note at all, don't include the template
@ -20727,31 +20746,47 @@ Current version indicated by LITEVER below.
if(wi_insertlocation>0)
{
truncated_anote = wistr + truncated_anote;
truncated_anote = substring_to_boundary(truncated_anote, max_anote_len);
}
else
{
truncated_memory += wistr;
}
truncated_memory = appendedsysprompt + truncate_memory(truncated_memory, max_mem_len, true);
//now we resize the context such that the memory and authors note can fit inside
truncated_context = substring_to_boundary(truncated_context, max_allowed_characters);
//append memory to the start of the context, clipping excess space if needed
//only do this processing if memory or anote is not blank
if (truncated_memory.length > 0 || current_anote.length > 0)
//if memory or authors note is not blank,
//append memory to the start of the context and insert anote somewhere before the ending
//if they are too long, clip excess space and resize the context so they can fit inside
if (appendedsysprompt.length > 0 || truncated_memory.length > 0 || truncated_anote.length > 0)
{
appendedsysprompt = replace_placeholders(appendedsysprompt,false,false,true);
truncated_memory = replace_placeholders(truncated_memory,false,false,true);
truncated_memory = appendedsysprompt + truncate_memory(truncated_memory, max_mem_len, true);
truncated_anote = replace_placeholders(truncated_anote,false,false,false);
truncated_anote = substring_to_boundary(truncated_anote, max_anote_len);
let min_context_len = Math.min(32, max_allowed_characters);
if(!is_using_kcpp_with_added_memory())
{
let augmented_len = truncated_memory.length + truncated_context.length + truncated_anote.length;
let excess_len = augmented_len - max_allowed_characters; //if > 0, then we exceeded context window
excess_len = excess_len < 0 ? 0 : excess_len;
let newlimit = (max_allowed_characters-excess_len) < 32 ? 32 : (max_allowed_characters-excess_len);
truncated_context = substring_to_boundary(truncated_context, newlimit); //must always have at least 32 chars from main context
let available_aux_len = max_allowed_characters - min_context_len;
if(truncated_anote.length > available_aux_len)
{
truncated_anote = substring_to_boundary(truncated_anote, available_aux_len);
truncated_memory = "";
}
else if(truncated_memory.length + truncated_anote.length > available_aux_len)
{
truncated_memory = truncate_memory(truncated_memory, available_aux_len - truncated_anote.length, true);
}
let newlimit = Math.max(min_context_len, max_allowed_characters - truncated_memory.length - truncated_anote.length);
truncated_context = substring_to_boundary(truncated_context, newlimit);
}
else
{
let available_anote_len = max_allowed_characters - min_context_len;
if(truncated_anote.length > available_anote_len)
{
truncated_anote = substring_to_boundary(truncated_anote, available_anote_len);
}
let newlimit = Math.max(min_context_len, max_allowed_characters - truncated_anote.length);
truncated_context = substring_to_boundary(truncated_context, newlimit);
}
//insert authors note 80 tokens before the ending (320 characters).
@ -20789,9 +20824,6 @@ Current version indicated by LITEVER below.
truncated_context = truncated_memory + truncated_context;
}
}
truncated_context = replace_placeholders(truncated_context,false,false,true);
if(is_using_kcpp_with_added_memory())
{
let tmp = repair_post_placeholders_fix(truncated_memory, truncated_context);
@ -32292,7 +32324,10 @@ Current version indicated by LITEVER below.
<input class="form-control" name="username" autocomplete="username" type="text" id="custom_oai_endpoint" placeholder="OpenAI API URL" value="" onblur="">
<input class="form-control" name="password" autocomplete="current-password" type="password" id="custom_oai_key" placeholder="API Key (Required)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br>
Model Choice:<br>
<div style="display:flex; align-items:center;">
<div style="padding:2px">Model Choice:</div>
<div style="padding:2px;margin-left:auto;" id="model_cost"></div>
</div>
<select title="OpenAI Model Selection" style="padding:4px;display:inline;width:calc(100% - 200px)" class="form-control" id="custom_oai_model" onchange="oai_model_change(true)">
<option value="gpt-3.5-turbo-instruct" selected="selected">gpt-3.5-turbo-instruct</option>
<option value="davinci-002">davinci-002</option>
@ -32480,7 +32515,9 @@ Current version indicated by LITEVER below.
<span class="color_green" style="font-weight: bold;">Please input Claude API URL and Key.</span><br><br>
<input class="form-control" type="text" id="custom_claude_endpoint" placeholder="Claude API URL" value="">
<input class="form-control" type="password" id="custom_claude_key" placeholder="Claude API Key (Required)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br>
Model Choice:<br>
<div style="display:flex; align-items:center;">
<div style="padding:2px">Model Choice:</div>
</div>
<select title="Claude AI Model Selection" style="padding:4px; width:calc(100% - 110px); display:inline-block" class="form-control" id="custom_claude_model" onload="toggleclaudemodel()" onchange="toggleclaudemodel()">
<option value="claude-opus-4-8">claude-opus-4-8</option>
<option value="claude-opus-4-7">claude-opus-4-7</option>