From ce4aaeb692ef8b65a14de51eec87801373779520 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Fri, 17 May 2024 21:00:16 +0530 Subject: [PATCH] SimpleChat: Use common helper logic wrt json data --- examples/server/public/simplechat.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/server/public/simplechat.js b/examples/server/public/simplechat.js index 13be5eb31..b29e65409 100644 --- a/examples/server/public/simplechat.js +++ b/examples/server/public/simplechat.js @@ -44,14 +44,29 @@ class SimpleChat { } } + /** + * Add needed fields wrt json object to be sent wrt LLM web services completions endpoint + * Convert the json into string. + * @param {Object} obj + */ + request_jsonstr(obj) { + obj["temperature"] = 0.7; + return JSON.stringify(obj); + } + + /** + * Return a string form of json object suitable for chat/completions + */ request_messages_jsonstr() { let req = { messages: this.xchat, - temperature: 0.7 } - return JSON.stringify(req); + return this.request_jsonstr(req); } + /** + * Return a string form of json object suitable for /completions + */ request_prompt_jsonstr() { let prompt = ""; for(const chat of this.xchat) { @@ -59,9 +74,8 @@ class SimpleChat { } let req = { prompt: prompt, - temperature: 0.7 } - return JSON.stringify(req); + return this.request_jsonstr(req); } }