SimpleChat:Allow system prompt to be set, if provided before user

This commit is contained in:
HanishKVC 2024-05-18 02:55:27 +05:30
parent 69817fe1de
commit ae52ad1675
2 changed files with 12 additions and 2 deletions

View file

@ -40,6 +40,7 @@
</div>
<hr>
<div id="chat">
<p> Enter the system prompt above, before entering/submitting any user query</p>
<p> Enter your text to the ai assistant below</p>
</div>

View file

@ -90,11 +90,19 @@ class SimpleChat {
/**
* Handle submit request by user
* @param {HTMLInputElement} inputSystem
* @param {HTMLInputElement} inputUser
* @param {HTMLDivElement} divChat
* @param {string} apiEP
*/
async function handle_submit(inputUser, divChat, apiEP) {
async function handle_submit(inputSystem, inputUser, divChat, apiEP) {
if (gChat.xchat.length == 0) {
let sysPrompt = inputSystem.value;
if (sysPrompt.length > 0) {
gChat.add(Roles.System, sysPrompt);
}
}
let content = inputUser?.value;
gChat.add(Roles.User, content);
@ -159,6 +167,7 @@ const gbCompletionFreshChatAlways = true;
function startme() {
let inputSystem = /** @type{HTMLInputElement} */(document.getElementById("system"));
let divChat = /** @type{HTMLDivElement} */(document.getElementById("chat"));
let btnSubmit = document.getElementById("submit");
let inputUser = /** @type{HTMLInputElement} */(document.getElementById("user"));
@ -172,7 +181,7 @@ function startme() {
if (inputUser.disabled) {
return;
}
handle_submit(inputUser, divChat, selectApiEP.value);
handle_submit(inputSystem, inputUser, divChat, selectApiEP.value);
});
inputUser?.addEventListener("keyup", (ev)=> {