From 72151aa634b8f47bb88fabcac6de2418aeeda0dd Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sat, 18 May 2024 03:16:30 +0530 Subject: [PATCH] SimpleChat:Alert user if they provide sysprompt late or change it --- examples/server/public_simplechat/simplechat.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index 35a74109e..1211628e6 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -98,11 +98,21 @@ class SimpleChat { */ async function handle_submit(inputSystem, inputUser, divChat, apiEP) { + let sysPrompt = inputSystem.value; if (gChat.xchat.length == 0) { - let sysPrompt = inputSystem.value; if (sysPrompt.length > 0) { gChat.add(Roles.System, sysPrompt); } + } else { + if (sysPrompt.length > 0) { + if (gChat.xchat[0].role !== Roles.System) { + console.error("ERRR:HandleSubmit:You need to specify system prompt before any user query, ignoring..."); + } else { + if (gChat.xchat[0].content !== sysPrompt) { + console.error("ERRR:HandleSubmit:You cant change system prompt, mid way through, ignoring..."); + } + } + } } let content = inputUser?.value;