From 872ee2c73d1b05fb407fc42077bffb77cbc9ceeb Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Thu, 30 May 2024 04:46:23 +0530 Subject: [PATCH] SimpleChat: Save message internally in handle_response itself This ensures that throwing the caught exception again for higher up logic, doesnt lose the response collated till that time. Go through theResp.assistant in catch block, just to keep simple consistency wrt backtracing just in case. Update the readme file. --- examples/server/public_simplechat/readme.md | 10 ++++++++++ examples/server/public_simplechat/simplechat.js | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/server/public_simplechat/readme.md b/examples/server/public_simplechat/readme.md index 83dec817d..1643485f8 100644 --- a/examples/server/public_simplechat/readme.md +++ b/examples/server/public_simplechat/readme.md @@ -108,6 +108,9 @@ Once inside * Using NewChat one can start independent chat sessions. * two independent chat sessions are setup by default. +* When you want to print, switching ChatHistoryInCtxt to Full and clicking on the chat session button of + interest, will display the full chat history till then wrt same, if you want full history for printing. + ## Devel note @@ -135,6 +138,13 @@ It is attached to the document object. Some of these can also be updated using t the logic assumes that the text sent from the server follows utf-8 encoding. + in streaming mode - if there is any exception, the logic traps the same and tries to ensure + that text generated till then is not lost. + + if a very long text is being generated, which leads to no user interaction for sometime and + inturn the machine goes into power saving mode or so, the platform may stop network connection, + leading to exception. + apiEP - select between /completions and /chat/completions endpoint provided by the server/ai-model. bCompletionFreshChatAlways - whether Completion mode collates complete/sliding-window history when diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index d77e27108..298ec8e60 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -428,6 +428,8 @@ class SimpleChat { this.latestResponse = ""; } catch (error) { theResp.assistant = this.latestResponse; + this.add(Roles.Assistant, theResp.assistant); + this.latestResponse = ""; throw error; } } else { @@ -438,6 +440,7 @@ class SimpleChat { theResp.assistant = du.trim_garbage_at_end(origMsg); theResp.trimmed = origMsg.substring(theResp.assistant.length); } + this.add(Roles.Assistant, theResp.assistant); return theResp; } @@ -601,7 +604,6 @@ class MultiChatUI { }); let theResp = await chat.handle_response(resp, apiEP, this.elDivChat); - chat.add(Roles.Assistant, theResp.assistant); if (chatId == this.curChatId) { chat.show(this.elDivChat); if (theResp.trimmed.length > 0) {