From 1e47a48b30aa3f446fe1cd54d451437e8f5a0106 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Mon, 27 May 2024 00:46:42 +0530 Subject: [PATCH] SimpleChat:UI: Add Select helper and use it wrt ChatHistoryInCtxt --- .../server/public_simplechat/simplechat.js | 11 +++++++ examples/server/public_simplechat/ui.mjs | 31 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index 8cc41e558..d96142ea2 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -535,6 +535,12 @@ class Me { this.bCompletionFreshChatAlways = true; this.bCompletionInsertStandardRolePrefix = false; this.iRecentUserMsgCnt = 2; + this.sRecentUserMsgCnt = { + "Full": -1, + "Last0": 1, + "Last1": 2, + "Last2": 3, + }; // Add needed fields wrt json object to be sent wrt LLM web services completions endpoint. this.chatRequestOptions = { "temperature": 0.7, @@ -580,6 +586,11 @@ class Me { }); elDiv.appendChild(bb); + let sel = ui.el_create_select("SetChatHistoryInCtxt", Object.keys(this.sRecentUserMsgCnt), "Last0", (val)=>{ + this.iRecentUserMsgCnt = this.sRecentUserMsgCnt[val]; + }); + elDiv.appendChild(sel); + } } diff --git a/examples/server/public_simplechat/ui.mjs b/examples/server/public_simplechat/ui.mjs index 73feedc93..e7aa20c16 100644 --- a/examples/server/public_simplechat/ui.mjs +++ b/examples/server/public_simplechat/ui.mjs @@ -83,3 +83,34 @@ export function el_create_boolbutton(id, texts, defaultValue, cb) { }) return el; } + +/** + * @param {string} id + * @param {string[]} options + * @param {string} defaultOption + * @param {function(string):void} cb + */ +export function el_create_select(id, options, defaultOption, cb) { + let el = document.createElement("select"); + el["xselected"] = defaultOption; + el["xoptions"] = structuredClone(options); + for(let cur of options) { + let op = document.createElement("option"); + op.value = cur; + op.innerText = cur; + if (cur == defaultOption) { + op.selected = true; + } + el.appendChild(op); + } + if (id) { + el.id = id; + el.name = id; + } + el.addEventListener('click', (ev)=>{ + let target = /** @type{HTMLSelectElement} */(ev.target); + console.log("DBUG:UI:Select:", id, ":", target.value); + cb(target.value); + }) + return el; +}