SimpleChat:Allow system prompt to be set, if provided before user
This commit is contained in:
parent
69817fe1de
commit
ae52ad1675
2 changed files with 12 additions and 2 deletions
|
@ -40,6 +40,7 @@
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div id="chat">
|
<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>
|
<p> Enter your text to the ai assistant below</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -90,11 +90,19 @@ class SimpleChat {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle submit request by user
|
* Handle submit request by user
|
||||||
|
* @param {HTMLInputElement} inputSystem
|
||||||
* @param {HTMLInputElement} inputUser
|
* @param {HTMLInputElement} inputUser
|
||||||
* @param {HTMLDivElement} divChat
|
* @param {HTMLDivElement} divChat
|
||||||
* @param {string} apiEP
|
* @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;
|
let content = inputUser?.value;
|
||||||
gChat.add(Roles.User, content);
|
gChat.add(Roles.User, content);
|
||||||
|
@ -159,6 +167,7 @@ const gbCompletionFreshChatAlways = true;
|
||||||
|
|
||||||
function startme() {
|
function startme() {
|
||||||
|
|
||||||
|
let inputSystem = /** @type{HTMLInputElement} */(document.getElementById("system"));
|
||||||
let divChat = /** @type{HTMLDivElement} */(document.getElementById("chat"));
|
let divChat = /** @type{HTMLDivElement} */(document.getElementById("chat"));
|
||||||
let btnSubmit = document.getElementById("submit");
|
let btnSubmit = document.getElementById("submit");
|
||||||
let inputUser = /** @type{HTMLInputElement} */(document.getElementById("user"));
|
let inputUser = /** @type{HTMLInputElement} */(document.getElementById("user"));
|
||||||
|
@ -172,7 +181,7 @@ function startme() {
|
||||||
if (inputUser.disabled) {
|
if (inputUser.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handle_submit(inputUser, divChat, selectApiEP.value);
|
handle_submit(inputSystem, inputUser, divChat, selectApiEP.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
inputUser?.addEventListener("keyup", (ev)=> {
|
inputUser?.addEventListener("keyup", (ev)=> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue