Skip to content

Commit 14ba205

Browse files
committed
SimpleChat: AutoCreate ChatRequestOptions settings to an extent
1 parent befa70f commit 14ba205

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

examples/server/public_simplechat/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ It is attached to the document object. Some of these can also be updated using t
177177
modify the existing options value or remove them, for now you can update this global var
178178
using browser's development-tools/console.
179179

180+
For string and numeric fields in chatRequestOptions, including even those added by a user
181+
at runtime by directly modifying gMe.chatRequestOptions, setting ui entries will be auto
182+
created.
183+
180184
headers - maintains the list of http headers sent when request is made to the server. By default
181185
Content-Type is set to application/json. Additionally Authorization entry is provided, which can
182186
be set if needed using the settings ui.

examples/server/public_simplechat/simplechat.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,37 @@ class Me {
817817

818818
}
819819

820+
/**
821+
* Auto create ui input elements for fields in ChatRequestOptions
822+
* Currently supports text and number field types.
823+
* @param {HTMLDivElement} elDiv
824+
*/
825+
show_settings_chatrequestoptions(elDiv) {
826+
let typeDict = {
827+
"string": "text",
828+
"number": "number",
829+
};
830+
let fs = document.createElement("fieldset");
831+
let legend = document.createElement("legend");
832+
legend.innerText = "ChatRequestOptions";
833+
fs.appendChild(legend);
834+
elDiv.appendChild(fs);
835+
for(const k in this.chatRequestOptions) {
836+
let val = this.chatRequestOptions[k];
837+
let type = typeof(val);
838+
if (!((type == "string") || (type == "number"))) {
839+
continue;
840+
}
841+
let inp = ui.el_creatediv_input(`Set${k}`, k, typeDict[type], this.chatRequestOptions[k], (val)=>{
842+
if (type == "number") {
843+
val = Number(val);
844+
}
845+
this.chatRequestOptions[k] = val;
846+
});
847+
fs.appendChild(inp.div);
848+
}
849+
}
850+
820851
/**
821852
* Show settings ui for configurable parameters, in the passed Div element.
822853
* @param {HTMLDivElement} elDiv
@@ -834,11 +865,6 @@ class Me {
834865
inp.el.placeholder = "Bearer OPENAI_API_KEY";
835866
elDiv.appendChild(inp.div);
836867

837-
inp = ui.el_creatediv_input("SetModel", "Model", "text", this.chatRequestOptions["model"], (val)=>{
838-
this.chatRequestOptions["model"] = val;
839-
});
840-
elDiv.appendChild(inp.div);
841-
842868
let bb = ui.el_creatediv_boolbutton("SetStream", "Stream", {true: "[+] yes stream", false: "[-] do oneshot"}, this.bStream, (val)=>{
843869
this.bStream = val;
844870
});
@@ -869,6 +895,8 @@ class Me {
869895
});
870896
elDiv.appendChild(sel.div);
871897

898+
this.show_settings_chatrequestoptions(elDiv);
899+
872900
}
873901

874902
}

0 commit comments

Comments
 (0)