From fe60655e1f87fca01d58e27e6097a1a2d75b9884 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Thu, 23 May 2024 03:42:02 +0530 Subject: [PATCH] SimpleChat:SC: Ensure proper clearing/reseting previous logic would have cleared/reset the xchat, without doing the same wrt iLastSys, thus leading to it pointing to a now non existent role-content entry. So if a user set a system prompt and used completion mode, it would have done the half stupid clear, after the model response was got. Inturn when user tries to send a new completion query, it would inturn lead to handle_user_submit trying to add/update system prompt if any, which will fail, bcas iLastSys will be still pointing to a non existant entry. This is fixed now, by having a proper clear helper wrt SC class. --- examples/server/public_simplechat/simplechat.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index 59710d330..5bcf9ed17 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -35,6 +35,11 @@ class SimpleChat { this.iLastSys = -1; } + clear() { + this.xchat = []; + this.iLastSys = -1; + } + /** * Add an entry into xchat * @param {string} role @@ -397,7 +402,7 @@ class MultiChatUI { // in a completion mode with multiple user-assistant chat data // from before to be sent/occur once. if ((apiEP == ApiEP.Completion) && (gbCompletionFreshChatAlways)) { - chat.xchat.length = 0; + chat.clear(); } this.ui_reset_userinput(); }