add ddim sampler

This commit is contained in:
Concedo 2025-05-22 21:28:01 +08:00
parent f125e724eb
commit e68a5f448c
3 changed files with 57 additions and 18 deletions

View file

@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
--> -->
<script> <script>
const LITEVER = 243; const LITEVER = 244;
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
var localflag = urlParams.get('local'); //this will be replaced automatically in embedded kcpp var localflag = urlParams.get('local'); //this will be replaced automatically in embedded kcpp
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_"; const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@ -3337,6 +3337,7 @@ Current version indicated by LITEVER below.
entersubmit: true, //enter sends the prompt entersubmit: true, //enter sends the prompt
darkmode: true, darkmode: true,
raw_instruct_tags: false, //experimental flag raw_instruct_tags: false, //experimental flag
show_endpoint_selector: false,
//section migrated from story itself //section migrated from story itself
extrastopseq: "", extrastopseq: "",
@ -4344,7 +4345,10 @@ Current version indicated by LITEVER below.
if (maxIndex === lastA) return get_instructstartplaceholder_end(); if (maxIndex === lastA) return get_instructstartplaceholder_end();
if (maxIndex === lastB) return get_instructendplaceholder_end(); if (maxIndex === lastB) return get_instructendplaceholder_end();
return instructsysplaceholder_end; return instructsysplaceholder_end;
}
function get_current_timestamp()
{
return "["+(new Date().toLocaleTimeString([], {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}))+"]";
} }
function remove_all_instruct_tags(text) function remove_all_instruct_tags(text)
@ -5625,7 +5629,7 @@ Current version indicated by LITEVER below.
{ {
continue; continue;
} }
if(synchro_pending_stream.includes(cur)) if(synchro_pending_stream.includes(cur) && synchro_pending_stream.trim().indexOf(cur) > 1) //don't trigger early stopping if the match is very early
{ {
cached_stop_seq = []; cached_stop_seq = [];
let need_clean_output = (synchro_pending_stream!="" && localsettings.opmode==1 && gametext_arr.length>0 && document.getElementById("useoaichatcompl").checked); let need_clean_output = (synchro_pending_stream!="" && localsettings.opmode==1 && gametext_arr.length>0 && document.getElementById("useoaichatcompl").checked);
@ -6091,6 +6095,7 @@ Current version indicated by LITEVER below.
//purge url params //purge url params
window.history.replaceState(null, null, window.location.pathname); window.history.replaceState(null, null, window.location.pathname);
} else if (foundScenario && foundScenario != "") { } else if (foundScenario && foundScenario != "") {
avoidwelcome = true;
display_scenarios(); display_scenarios();
document.getElementById("scenariosearch").value = escape_html(foundScenario); document.getElementById("scenariosearch").value = escape_html(foundScenario);
scenario_search(); scenario_search();
@ -6102,6 +6107,7 @@ Current version indicated by LITEVER below.
//purge url params //purge url params
window.history.replaceState(null, null, window.location.pathname); window.history.replaceState(null, null, window.location.pathname);
} else if (foundScenarioSource) { } else if (foundScenarioSource) {
avoidwelcome = true;
console.log(foundScenarioSource, urlParams.get(foundScenarioSource.urlParam)); console.log(foundScenarioSource, urlParams.get(foundScenarioSource.urlParam));
display_scenarios(); display_scenarios();
import_scenario(foundScenarioSource, urlParams.get(foundScenarioSource.urlParam)); import_scenario(foundScenarioSource, urlParams.get(foundScenarioSource.urlParam));
@ -6110,6 +6116,7 @@ Current version indicated by LITEVER below.
} }
else if (foundQuery && foundQuery != "") else if (foundQuery && foundQuery != "")
{ {
avoidwelcome = true;
window.history.replaceState(null, null, window.location.pathname); window.history.replaceState(null, null, window.location.pathname);
if (localsettings.persist_session && !safe_to_overwrite()) { if (localsettings.persist_session && !safe_to_overwrite()) {
msgboxYesNo("You already have an existing persistent story. Do you want to overwrite it?","Overwrite Story Warning",()=>{ msgboxYesNo("You already have an existing persistent story. Do you want to overwrite it?","Overwrite Story Warning",()=>{
@ -6127,6 +6134,10 @@ Current version indicated by LITEVER below.
prepare_submit_generation(); prepare_submit_generation();
} }
} }
if(avoidwelcome)
{
close_welcome_panel(false);
}
} }
@ -11800,6 +11811,7 @@ Current version indicated by LITEVER below.
document.getElementById("instruct_systag_end").value = localsettings.instruct_systag_end; document.getElementById("instruct_systag_end").value = localsettings.instruct_systag_end;
document.getElementById("instruct_endtag_end").value = localsettings.instruct_endtag_end; document.getElementById("instruct_endtag_end").value = localsettings.instruct_endtag_end;
document.getElementById("raw_instruct_tags").checked = localsettings.raw_instruct_tags; document.getElementById("raw_instruct_tags").checked = localsettings.raw_instruct_tags;
document.getElementById("show_endpoint_selector").checked = localsettings.show_endpoint_selector;
document.getElementById("min_p").value = localsettings.min_p; document.getElementById("min_p").value = localsettings.min_p;
document.getElementById("dynatemp_range").value = localsettings.dynatemp_range; document.getElementById("dynatemp_range").value = localsettings.dynatemp_range;
document.getElementById("dynatemp_exponent").value = localsettings.dynatemp_exponent; document.getElementById("dynatemp_exponent").value = localsettings.dynatemp_exponent;
@ -12324,6 +12336,7 @@ Current version indicated by LITEVER below.
localsettings.eos_ban_mode = document.getElementById("eos_ban_mode").value; localsettings.eos_ban_mode = document.getElementById("eos_ban_mode").value;
localsettings.persist_session = (document.getElementById("persist_session").checked ? true : false); localsettings.persist_session = (document.getElementById("persist_session").checked ? true : false);
localsettings.raw_instruct_tags = (document.getElementById("raw_instruct_tags").checked ? true : false); localsettings.raw_instruct_tags = (document.getElementById("raw_instruct_tags").checked ? true : false);
localsettings.show_endpoint_selector = (document.getElementById("show_endpoint_selector").checked ? true : false);
if(document.getElementById("opmode").value==1) if(document.getElementById("opmode").value==1)
{ {
localsettings.gui_type_story = document.getElementById("gui_type").value; localsettings.gui_type_story = document.getElementById("gui_type").value;
@ -13275,6 +13288,7 @@ Current version indicated by LITEVER below.
function restart_new_game(save = true, keep_memory = false) { function restart_new_game(save = true, keep_memory = false) {
xtts_is_playing = false; xtts_is_playing = false;
idle_timer = 0; idle_timer = 0;
idle_triggered_counter = 0;
gametext_arr = []; gametext_arr = [];
redo_arr = []; redo_arr = [];
last_request_str = "No Requests Available"; last_request_str = "No Requests Available";
@ -14580,7 +14594,7 @@ Current version indicated by LITEVER below.
} }
if(localsettings.inject_timestamps) if(localsettings.inject_timestamps)
{ {
newgen = "["+(new Date().toLocaleTimeString([], {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}))+"] " + newgen; newgen = get_current_timestamp() + " " + newgen;
} }
//append instruction for instruct mode //append instruction for instruct mode
@ -14620,7 +14634,7 @@ Current version indicated by LITEVER below.
let injecttime = ""; let injecttime = "";
if(localsettings.inject_timestamps) if(localsettings.inject_timestamps)
{ {
injecttime = " ["+(new Date().toLocaleTimeString([], {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}))+"]"; injecttime = " " + get_current_timestamp();
} }
newgen = "\n" + get_my_multiplayer_chatname() + ":"+ injecttime +" "+ newgen + ""; newgen = "\n" + get_my_multiplayer_chatname() + ":"+ injecttime +" "+ newgen + "";
return newgen; return newgen;
@ -14899,7 +14913,7 @@ Current version indicated by LITEVER below.
pending_context_preinjection = "\n"+co + ":"; pending_context_preinjection = "\n"+co + ":";
if(localsettings.inject_timestamps) if(localsettings.inject_timestamps)
{ {
pending_context_preinjection += " ["+(new Date().toLocaleTimeString([], {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}))+"]"; pending_context_preinjection += " " + get_current_timestamp();
} }
} }
else else
@ -14939,7 +14953,7 @@ Current version indicated by LITEVER below.
let endmatcher = get_instructendplaceholder(); let endmatcher = get_instructendplaceholder();
if (truncated_context.toLowerCase().trim().endsWith(endmatcher.toLowerCase().trim())) { if (truncated_context.toLowerCase().trim().endsWith(endmatcher.toLowerCase().trim())) {
if (localsettings.inject_timestamps) { if (localsettings.inject_timestamps) {
pending_context_preinjection += "[" + (new Date().toLocaleTimeString([], { year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })) + "]"; pending_context_preinjection += get_current_timestamp();
} }
if (localsettings.inject_chatnames_instruct && localsettings.chatopponent!="") { if (localsettings.inject_chatnames_instruct && localsettings.chatopponent!="") {
if (localsettings.inject_timestamps) { if (localsettings.inject_timestamps) {
@ -15572,7 +15586,7 @@ Current version indicated by LITEVER below.
let prompt = submit_payload.prompt; let prompt = submit_payload.prompt;
submit_payload = submit_payload.params; submit_payload = submit_payload.params;
submit_payload.prompt = prompt; submit_payload.prompt = prompt;
let showlog = (document.getElementById("remoteconsolelog").checked ? true : false); let showlog = false;
submit_payload.quiet = !showlog; submit_payload.quiet = !showlog;
//for vesion 1.2.2 and later, send stopper tokens for chat and instruct //for vesion 1.2.2 and later, send stopper tokens for chat and instruct
@ -16313,8 +16327,11 @@ Current version indicated by LITEVER below.
case "DPM++ 2M": case "DPM++ 2M":
usedsampler = "k_dpmpp_2m"; usedsampler = "k_dpmpp_2m";
break; break;
case "DDIM":
usedsampler = "DDIM";
break;
default: default:
usedsampler = "k_euler_a"; usedsampler = "k_euler";
break; break;
} }
@ -17529,7 +17546,7 @@ Current version indicated by LITEVER below.
if(localsettings.inject_timestamps) if(localsettings.inject_timestamps)
{ {
pending_context_preinjection += "["+(new Date().toLocaleTimeString([], {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}))+"]"; pending_context_preinjection += get_current_timestamp();
} }
} }
} }
@ -18891,7 +18908,7 @@ Current version indicated by LITEVER below.
} }
//console.log("FT:" + fulltxt); //console.log("FT:" + fulltxt);
if(fulltxt=="" && gametext_arr.length == 0 && synchro_pending_stream=="" && pending_response_id!="") if(fulltxt == "" && gametext_arr.length == 0 && synchro_pending_stream=="" && pending_response_id!="")
{ {
fulltxt = "Generating..."; fulltxt = "Generating...";
} }
@ -18924,7 +18941,15 @@ Current version indicated by LITEVER below.
}else{ }else{
document.getElementById("topbtn_customendpt").classList.remove("hidden"); document.getElementById("topbtn_customendpt").classList.remove("hidden");
} }
document.getElementById("topbtn_ai").classList.add("hidden"); if(localsettings.show_endpoint_selector)
{
document.getElementById("topbtn_ai").classList.remove("hidden");
}
else
{
document.getElementById("topbtn_ai").classList.add("hidden");
}
document.getElementById("topbtn_newgame").classList.remove("hidden"); document.getElementById("topbtn_newgame").classList.remove("hidden");
document.getElementById("topbtn_save_load").classList.remove("hidden"); document.getElementById("topbtn_save_load").classList.remove("hidden");
document.getElementById("topbtn_scenarios").classList.add("hidden"); document.getElementById("topbtn_scenarios").classList.add("hidden");
@ -18933,7 +18958,7 @@ Current version indicated by LITEVER below.
document.getElementById("topbtn_reconnect").classList.add("hidden"); document.getElementById("topbtn_reconnect").classList.add("hidden");
document.getElementById("topbtn_customendpt").classList.add("hidden"); document.getElementById("topbtn_customendpt").classList.add("hidden");
if(localflag) if(localflag && !localsettings.show_endpoint_selector)
{ {
document.getElementById("topbtn_ai").classList.add("hidden"); document.getElementById("topbtn_ai").classList.add("hidden");
}else{ }else{
@ -19028,7 +19053,13 @@ Current version indicated by LITEVER below.
} }
else if (!inEditMode && isAestheticUiStyle) else if (!inEditMode && isAestheticUiStyle)
{ {
let textToRender = (gametext_arr.length == 0 ? document.getElementById("gametext").innerHTML : concat_gametext(false, "", "", "", true)); let textToRender = "";
let prepToGen = (gametext_arr.length == 0 && synchro_pending_stream == "" && pending_response_id != "");
if (gametext_arr.length == 0 && (prepToGen || pending_response_id == "")) {
textToRender = document.getElementById("gametext").innerHTML;
} else {
textToRender = concat_gametext(false, "", "", "", true);
}
textToRender = apply_display_only_regex(textToRender); textToRender = apply_display_only_regex(textToRender);
textToRender = replace_placeholders(textToRender,true); textToRender = replace_placeholders(textToRender,true);
@ -20871,7 +20902,7 @@ Current version indicated by LITEVER below.
if(localsettings.inject_timestamps) if(localsettings.inject_timestamps)
{ {
userinput = "["+(new Date().toLocaleTimeString([], {year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit'}))+"] " + userinput; userinput = get_current_timestamp() + " " + userinput;
} }
//append instruction for instruct mode //append instruction for instruct mode
@ -22909,6 +22940,7 @@ Current version indicated by LITEVER below.
<option value="Heun">Heun</option> <option value="Heun">Heun</option>
<option value="DPM2">DPM2</option> <option value="DPM2">DPM2</option>
<option value="LCM">LCM</option> <option value="LCM">LCM</option>
<option value="DDIM">DDIM</option>
<option value="DPM++ 2M">DPM++ 2M</option> <option value="DPM++ 2M">DPM++ 2M</option>
</select> </select>
</div> </div>
@ -23248,6 +23280,11 @@ Current version indicated by LITEVER below.
class="helptext">Does not insert instruct placeholders, only uses raw tags</span></span></div> class="helptext">Does not insert instruct placeholders, only uses raw tags</span></span></div>
<input title="Raw Instruct Tags" type="checkbox" id="raw_instruct_tags" style="margin:0px 0px 0px 0px;"> <input title="Raw Instruct Tags" type="checkbox" id="raw_instruct_tags" style="margin:0px 0px 0px 0px;">
</div> </div>
<div class="settinglabel">
<div class="justifyleft settingsmall">ShowEndpointSelector <span class="helpicon">?<span
class="helptext">Allows you to change the connected custom endpoint at runtime even in local mode.</span></span></div>
<input title="Show Local Endpoint Selector" type="checkbox" id="show_endpoint_selector" style="margin:0px 0px 0px 0px;">
</div>
</div> </div>
<div class="settingitem wide"> <div class="settingitem wide">
@ -23651,8 +23688,6 @@ Current version indicated by LITEVER below.
<input class="form-control" title="Enter KoboldCpp Custom Endpoint" id="customkoboldendpoint" placeholder="https://sample-remote-address.trycloudflare.com" value=""> <input class="form-control" title="Enter KoboldCpp Custom Endpoint" id="customkoboldendpoint" placeholder="https://sample-remote-address.trycloudflare.com" value="">
<input class="form-control" title="Enter KoboldCpp API Key" type="password" id="customkoboldkey" placeholder="KoboldAI API Key (Optional)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br> <input class="form-control" title="Enter KoboldCpp API Key" type="password" id="customkoboldkey" placeholder="KoboldAI API Key (Optional)" value="" onfocus="focus_api_keys()" onblur="blur_api_keys()"><br>
<div class="borderbox flex flex-push-right"> <div class="borderbox flex flex-push-right">
<input type="checkbox" id="remoteconsolelog">
<div class="box-label" title="Will display outputs to the remote endpoint's console logs, useful for debugging.">Show Console Logging</div>
</div> </div>
</div> </div>
<div id="oaicustom" class="menutext hidden"> <div id="oaicustom" class="menutext hidden">

View file

@ -2933,7 +2933,7 @@ Change Mode<br>
if friendlysdmodelname=="inactive" or fullsdmodelpath=="": if friendlysdmodelname=="inactive" or fullsdmodelpath=="":
response_body = (json.dumps([]).encode()) response_body = (json.dumps([]).encode())
else: else:
response_body = (json.dumps([{"name":"Euler","aliases":["k_euler"],"options":{}},{"name":"Euler a","aliases":["k_euler_a","k_euler_ancestral"],"options":{}},{"name":"Heun","aliases":["k_heun"],"options":{}},{"name":"DPM2","aliases":["k_dpm_2"],"options":{}},{"name":"DPM++ 2M","aliases":["k_dpmpp_2m"],"options":{}},{"name":"LCM","aliases":["k_lcm"],"options":{}}]).encode()) response_body = (json.dumps([{"name":"Euler","aliases":["k_euler"],"options":{}},{"name":"Euler a","aliases":["k_euler_a","k_euler_ancestral"],"options":{}},{"name":"Heun","aliases":["k_heun"],"options":{}},{"name":"DPM2","aliases":["k_dpm_2"],"options":{}},{"name":"DPM++ 2M","aliases":["k_dpmpp_2m"],"options":{}},{"name":"DDIM","aliases":["ddim"],"options":{}},{"name":"LCM","aliases":["k_lcm"],"options":{}}]).encode())
elif self.path.endswith('/sdapi/v1/latent-upscale-modes'): elif self.path.endswith('/sdapi/v1/latent-upscale-modes'):
response_body = (json.dumps([]).encode()) response_body = (json.dumps([]).encode())
elif self.path.endswith('/sdapi/v1/upscalers'): elif self.path.endswith('/sdapi/v1/upscalers'):

View file

@ -410,6 +410,10 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
{ {
sd_params->sample_method = sample_method_t::LCM; sd_params->sample_method = sample_method_t::LCM;
} }
else if(sampler=="ddim")
{
sd_params->sample_method = sample_method_t::DDIM_TRAILING;
}
else if(sampler=="dpm++ 2m karras" || sampler=="dpm++ 2m" || sampler=="k_dpmpp_2m") else if(sampler=="dpm++ 2m karras" || sampler=="dpm++ 2m" || sampler=="k_dpmpp_2m")
{ {
sd_params->sample_method = sample_method_t::DPMPP2M; sd_params->sample_method = sample_method_t::DPMPP2M;