SimpleChat: Move baseUrl to Me and inturn gMe

This should allow easy updating of the base url at runtime by the
end user.
This commit is contained in:
HanishKVC 2024-05-29 19:04:14 +05:30
parent ace37042fa
commit 104848b097

View file

@ -11,17 +11,28 @@ class Roles {
static Assistant = "assistant"; static Assistant = "assistant";
} }
let gBaseURL = "http://127.0.0.1:8080";
class ApiEP { class ApiEP {
static Type = { static Type = {
Chat: "chat", Chat: "chat",
Completion: "completion", Completion: "completion",
} }
static Url = { static UrlSuffix = {
'chat': `${gBaseURL}/chat/completions`, 'chat': `/chat/completions`,
'completion': `${gBaseURL}/completions`, 'completion': `/completions`,
} }
/**
* Build the url from given baseUrl and apiEp id.
* @param {string} baseUrl
* @param {string} apiEP
*/
static Url(baseUrl, apiEP) {
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length-1);
}
return `${baseUrl}${this.UrlSuffix[apiEP]}`;
}
} }
@ -542,7 +553,7 @@ class MultiChatUI {
} }
chat.show(this.elDivChat); chat.show(this.elDivChat);
let theUrl = ApiEP.Url[apiEP]; let theUrl = ApiEP.Url(gMe.baseURL, apiEP);
let theBody = chat.request_jsonstr(apiEP); let theBody = chat.request_jsonstr(apiEP);
this.elInUser.value = "working..."; this.elInUser.value = "working...";
@ -649,6 +660,7 @@ class MultiChatUI {
class Me { class Me {
constructor() { constructor() {
this.baseURL = "http://127.0.0.1:8080";
this.defaultChatIds = [ "Default", "Other" ]; this.defaultChatIds = [ "Default", "Other" ];
this.multiChat = new MultiChatUI(); this.multiChat = new MultiChatUI();
this.bStream = true; this.bStream = true;