From 3c11098d1eb4f4a53194efe00e555b0aa69ebb5f Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Wed, 22 May 2024 22:10:52 +0530 Subject: [PATCH] SimpleChat:CompletionMode: Allow control of Role: prefix --- examples/server/public_simplechat/simplechat.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index 51986ad9c..4209feb6b 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -97,11 +97,15 @@ class SimpleChat { /** * Return a string form of json object suitable for /completions + * @param {boolean} bInsertStandardRolePrefix Insert ": " as prefix wrt each role's message */ - request_prompt_jsonstr() { + request_prompt_jsonstr(bInsertStandardRolePrefix) { let prompt = ""; for(const chat of this.xchat) { - prompt += `${chat.role}: ${chat.content}\n`; + if (bInsertStandardRolePrefix) { + prompt += `${chat.role}: `; + } + prompt += `${chat.content}\n`; } let req = { prompt: prompt, @@ -174,6 +178,7 @@ let gChatURL = { 'completion': `${gBaseURL}/completions`, } const gbCompletionFreshChatAlways = true; +let gbCompletionInsertStandardRolePrefix = true; /** @@ -346,7 +351,7 @@ class MultiChatUI { if (apiEP == ApiEP.Chat) { theBody = chat.request_messages_jsonstr(); } else { - theBody = chat.request_prompt_jsonstr(); + theBody = chat.request_prompt_jsonstr(gbCompletionInsertStandardRolePrefix); } this.elInUser.value = "working...";