Skip to content

Commit eafe36f

Browse files
ConcedoConcedo
Concedo
authored and
Concedo
committedJul 29, 2024
auto guess external oai endpoint protocol if not specified
1 parent 840dfb0 commit eafe36f

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed
 

‎index.html

+28-8
Original file line numberDiff line numberDiff line change
@@ -3384,10 +3384,7 @@
33843384
let is_local = false;
33853385

33863386
if (url) {
3387-
is_local = (url.toLowerCase().includes("localhost") ||
3388-
url.toLowerCase().includes("127.0.0.1") ||
3389-
url.toLowerCase().includes("192.168.") ||
3390-
!url.toLowerCase().includes("."));
3387+
is_local = is_local_url(url);
33913388
}
33923389

33933390
if ((uses_cors_proxy||proxy_by_default) && !is_local) {
@@ -5316,6 +5313,17 @@
53165313
}
53175314
}
53185315

5316+
function is_local_url(target_url)
5317+
{
5318+
let is_local = (target_url.toLowerCase().includes("localhost")
5319+
|| target_url.toLowerCase().includes("127.0.0.1")
5320+
|| target_url.toLowerCase().includes("192.168.")
5321+
|| target_url.toLowerCase().includes("10.0.0.")
5322+
|| target_url.toLowerCase().includes("://10.0.")
5323+
|| !target_url.toLowerCase().includes(".")); //hostname without dots cannot be wan accessible
5324+
return is_local;
5325+
}
5326+
53195327
function is_browser_supports_sse()
53205328
{
53215329
return (self.TransformStream!=null && self.TextDecoderStream!=null && self.WritableStream!=null);
@@ -8100,6 +8108,11 @@
81008108
{
81018109
desired_oai_ep = desired_oai_ep.slice(0, -1);
81028110
}
8111+
if(!desired_oai_ep.includes("://")) //user did not add http/https
8112+
{
8113+
let is_local = is_local_url(desired_oai_ep);
8114+
desired_oai_ep = (is_local?"http://":"https://") + desired_oai_ep;
8115+
}
81038116
if (document.getElementById("oaiaddversion").checked)
81048117
{
81058118
if(desired_oai_ep!="" && desired_oai_ep.length > 4 && !desired_oai_ep.slice(-4).toLowerCase().includes("/v") && !desired_oai_ep.toLowerCase().includes("/v1/")) {
@@ -8355,6 +8368,11 @@
83558368
{
83568369
desiredkoboldendpoint = desiredkoboldendpoint.split("/api")[0];
83578370
}
8371+
if(!desiredkoboldendpoint.includes("://")) //user did not add http/https
8372+
{
8373+
let is_local = is_local_url(desiredkoboldendpoint);
8374+
desiredkoboldendpoint = (is_local?"http://":"https://") + desiredkoboldendpoint;
8375+
}
83588376

83598377
let urls1 = [
83608378
apply_proxy_url(desiredkoboldendpoint + kobold_custom_mdl_endpoint),
@@ -8575,10 +8593,7 @@
85758593
//if it still fails, then show error
85768594
console.log("Error: " + error);
85778595

8578-
let is_local = (custom_kobold_endpoint.toLowerCase().includes("localhost")
8579-
|| custom_kobold_endpoint.toLowerCase().includes("127.0.0.1")
8580-
|| custom_kobold_endpoint.toLowerCase().includes("192.168.")
8581-
|| !custom_kobold_endpoint.toLowerCase().includes(".")); //hostname without dots cannot be wan accessible
8596+
let is_local = is_local_url(custom_kobold_endpoint);
85828597

85838598
if (uses_cors_proxy || is_local) {
85848599
if(is_local && sublocalpathname!="")
@@ -8625,6 +8640,11 @@
86258640
{
86268641
desired_oai_ep = desired_oai_ep.slice(0, -1);
86278642
}
8643+
if(!desired_oai_ep.includes("://")) //user did not add http/https
8644+
{
8645+
let is_local = is_local_url(desired_oai_ep);
8646+
desired_oai_ep = (is_local?"http://":"https://") + desired_oai_ep;
8647+
}
86288648
if (document.getElementById("oaiaddversion").checked)
86298649
{
86308650
if(desired_oai_ep!="" && desired_oai_ep.length > 4 && !desired_oai_ep.slice(-4).toLowerCase().includes("/v") && !desired_oai_ep.toLowerCase().includes("/v1/")) {

0 commit comments

Comments
 (0)