Skip to content

Commit 33bc9f5

Browse files
ConcedoConcedo
Concedo
authored and
Concedo
committed
minor refactor custom oai
1 parent e01b208 commit 33bc9f5

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

index.html

+34-22
Original file line numberDiff line numberDiff line change
@@ -7875,34 +7875,49 @@
78757875
}
78767876
}
78777877

7878+
function get_oai_model_dropdown()
7879+
{
7880+
let ddval = document.getElementById("customapidropdown").value;
7881+
switch(ddval)
7882+
{
7883+
case 3:
7884+
return document.getElementById("custom_openrouter_model");
7885+
case 7:
7886+
return document.getElementById("custom_mistralai_model");
7887+
default:
7888+
return document.getElementById("custom_oai_model");
7889+
}
7890+
}
7891+
function ep_should_always_use_chat_completions()
7892+
{
7893+
let epchoice = document.getElementById("customapidropdown").value;
7894+
return (epchoice==3 || epchoice==7);
7895+
}
7896+
78787897
function select_custom_oai_model()
78797898
{
7880-
let isOpenrouter = (document.getElementById("customapidropdown").value==3);
7881-
let isMistralai = (document.getElementById("customapidropdown").value==7);
78827899
inputBox("Enter custom model name","Custom Model Name",localsettings.saved_oai_custommodel,"", ()=>{
78837900
let coai = getInputBoxValue().trim();
7884-
let dropdown = (isMistralai?document.getElementById("custom_mistralai_model"):(isOpenrouter?document.getElementById("custom_openrouter_model"):document.getElementById("custom_oai_model")));
7885-
let mdlopt = (isMistralai?document.getElementById("custom_mistralai_model_option"):(isOpenrouter?"custom_openrouter_model_option":"custom_oai_model_option"));
7901+
let dropdown = get_oai_model_dropdown();
7902+
var mdlopt = dropdown.querySelector('option.custom_model_option');
78867903
if(coai!="")
78877904
{
7888-
document.getElementById(mdlopt).value = coai;
7889-
document.getElementById(mdlopt).innerText = coai;
7890-
document.getElementById(mdlopt).style.display = "";
7905+
mdlopt.value = coai;
7906+
mdlopt.innerText = coai;
7907+
mdlopt.style.display = "";
78917908
dropdown.selectedIndex = dropdown.options.length - 1;
78927909
}
7893-
oai_model_change(isOpenrouter||isMistralai);
7910+
oai_model_change(ep_should_always_use_chat_completions());
78947911
},false);
78957912
}
78967913
function oai_model_change(autotoggle_check = false)
78977914
{
7898-
let isOpenrouter = (document.getElementById("customapidropdown").value==3);
7899-
let isMistralai = (document.getElementById("customapidropdown").value==7);
7900-
let dropdown = (isMistralai?document.getElementById("custom_mistralai_model"):(isOpenrouter?document.getElementById("custom_openrouter_model"):document.getElementById("custom_oai_model")));
7915+
let dropdown = get_oai_model_dropdown();
79017916
let non_completions = (dropdown.value.includes("davinci-002") || dropdown.value.includes("text-davinci-003") || dropdown.value.includes("text-davinci-002")
79027917
|| dropdown.value.includes("text-davinci-001") || dropdown.value.includes("gpt-3.5-turbo-instruct") || dropdown.value == "davinci");
79037918
if(autotoggle_check)
79047919
{
7905-
if(isMistralai || isOpenrouter || dropdown.selectedIndex==dropdown.options.length-1)
7920+
if(ep_should_always_use_chat_completions() || dropdown.selectedIndex==dropdown.options.length-1)
79067921
{
79077922
document.getElementById("useoaichatcompl").checked = true;
79087923
} else {
@@ -7958,8 +7973,7 @@
79587973
if (!data.error && data.data && data.data.length > 0)
79597974
{
79607975
let isOpenrouter = (document.getElementById("customapidropdown").value==3);
7961-
let isMistralai = (document.getElementById("customapidropdown").value==7);
7962-
let dropdown = (isMistralai?document.getElementById("custom_mistralai_model"):(isOpenrouter?document.getElementById("custom_openrouter_model"):document.getElementById("custom_oai_model")));
7976+
let dropdown = get_oai_model_dropdown();
79637977
var lastOption = dropdown.lastElementChild;
79647978
for (var i = dropdown.options.length - 1; i >= 0; i--) {
79657979
var option = dropdown.options[i];
@@ -8065,7 +8079,7 @@
80658079
document.getElementById("custom_oai_key").value = localsettings.saved_mistralai_key;
80668080
document.getElementById("custom_oai_endpoint").value = default_mistralai_base;
80678081
}
8068-
else
8082+
else //openrouter supports autofetch
80698083
{
80708084
document.getElementById("oaidesc").classList.add("hidden");
80718085
document.getElementById("openrouterdesc").classList.remove("hidden");
@@ -8084,7 +8098,7 @@
80848098
}
80858099
}
80868100
}
8087-
oai_model_change(epchoice==3 || epchoice==7 || force_autotoggle_chatcompl);
8101+
oai_model_change(ep_should_always_use_chat_completions() || force_autotoggle_chatcompl);
80888102
toggleoaichatcompl();
80898103
}
80908104
else if(epchoice==4)
@@ -8480,9 +8494,7 @@
84808494
}
84818495
localsettings.saved_oai_role = document.getElementById("oairoledropdown").value;
84828496
localsettings.saved_oai_jailbreak2 = document.getElementById("jailbreakprompttext2").value;
8483-
let isOpenrouter = (document.getElementById("customapidropdown").value==3);
8484-
let isMistralai = (document.getElementById("customapidropdown").value==7);
8485-
let dropdown = (isMistralai?document.getElementById("custom_mistralai_model"):(isOpenrouter?document.getElementById("custom_openrouter_model"):document.getElementById("custom_oai_model")));
8497+
let dropdown = get_oai_model_dropdown();
84868498
custom_oai_model = dropdown.value.trim();
84878499
localsettings.saved_oai_custommodel = custom_oai_model;
84888500
selected_models = [{ "performance": 100.0, "queued": 0.0, "eta": 0, "name": custom_oai_model, "count": 1 }];
@@ -17069,7 +17081,7 @@
1706917081
<option value="gpt-4-turbo">gpt-4-turbo</option>
1707017082
<option value="gpt-4o">gpt-4o</option>
1707117083
<option value="gpt-4-32k">gpt-4-32k</option>
17072-
<option style="display:none;" id="custom_oai_model_option" value="custom">[Custom]</option>
17084+
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
1707317085
</select>
1707417086
<select style="padding:4px;display:inline;width:calc(100% - 220px)" class="form-control hidden" id="custom_openrouter_model" onchange="oai_model_change(true)">
1707517087
<option value="openai/gpt-3.5-turbo">openai/gpt-3.5-turbo</option>
@@ -17079,7 +17091,7 @@
1707917091
<option value="gryphe/mythomax-l2-13b">gryphe/mythomax-l2-13b</option>
1708017092
<option value="huggingfaceh4/zephyr-7b-beta">huggingfaceh4/zephyr-7b-beta</option>
1708117093
<option value="anthropic/claude-2">anthropic/claude-2</option>
17082-
<option style="display:none;" id="custom_openrouter_model_option" value="custom">[Custom]</option>
17094+
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
1708317095
</select>
1708417096
<select style="padding:4px;display:inline;width:calc(100% - 220px)" class="form-control hidden" id="custom_mistralai_model" onchange="oai_model_change(true)">
1708517097
<option value="open-mistral-7b">open-mistral-7b</option>
@@ -17089,7 +17101,7 @@
1708917101
<option value="open-mixtral-8x22b">open-mixtral-8x22b</option>
1709017102
<option value="mistral-medium">mistral-medium</option>
1709117103
<option value="mistral-large-latest">mistral-large-latest</option>
17092-
<option style="display:none;" id="custom_mistralai_model_option" value="custom">[Custom]</option>
17104+
<option style="display:none;" class="custom_model_option" value="custom">[Custom]</option>
1709317105
</select>
1709417106
<button type="button" class="btn btn-primary" style="display:inline;width:105px;" id="oaifetchlist" onclick="oai_fetch_models()">Fetch List</button>
1709517107
<button type="button" class="btn btn-primary" style="display:inline;width:105px;" id="oaiusecustom" onclick="select_custom_oai_model()">Use Custom</button>

0 commit comments

Comments
 (0)