From a2a0a378a96a38add2c09e3a88e803dba6014dc7 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Wed, 12 Nov 2025 23:28:47 +0530 Subject: [PATCH] SimpleChatTCRV: Response handling try catch, update errors Had forgotten to move the one shot resp into try catch before. Fixed it. Ensure both oneshot multipart resp try catch Add some todos for later. Add a new check wrt response being normal or a error related one ie the content is actually a error message. --- tools/server/public_simplechat/readme.md | 7 +++-- tools/server/public_simplechat/simplechat.js | 32 ++++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index b57fe0c3aa..f0366bf98a 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -762,8 +762,11 @@ same when saved chat is loaded. MAYBE make the settings in general chat session specific, rather than the current global config flow. -Use indexedDB instead of localStorage for saving chat sessions, provided it is allocated more storage -space by browsers. +Have unique id or use the index into chat messages array wrt each chat message in a chat session, so that +it is easy to identify and remove chat messages from the UI even in sliding window mode. + +Have a seperate helper to show the user input area, based on set state. And have support for multiple images +if the models support same. ### Debuging the handshake and beyond diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index c83fd45721..14403c18ab 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -303,6 +303,16 @@ class ChatMessageEx { delete(this.ns[key]) } + /** + * Cross check if the got packet has error. + * @param {any} nwo + */ + update_checkerror(nwo) { + if (nwo["error"]) { + throw new Error(`ChatMessageEx:UpdateCheckError:${nwo["error"]}`); + } + } + /** * Update based on the drip by drip data got from network in streaming mode. * Tries to support both Chat and Completion endpoints @@ -311,6 +321,7 @@ class ChatMessageEx { */ update_stream(nwo, apiEP) { console.debug(nwo, apiEP) + this.update_checkerror(nwo) if (apiEP == ApiEP.Type.Chat) { if (nwo["choices"][0]["finish_reason"] === null) { let content = nwo["choices"][0]["delta"]["content"]; @@ -363,6 +374,7 @@ class ChatMessageEx { * @param {string} apiEP */ update_oneshot(nwo, apiEP) { + this.update_checkerror(nwo) if (apiEP == ApiEP.Type.Chat) { let curContent = nwo["choices"][0]["message"]["content"]; if (curContent != undefined) { @@ -853,19 +865,19 @@ class SimpleChat { */ async handle_response(resp, apiEP, elDiv) { let theResp = null; - if (this.me.chatProps.stream) { - try { + try { + if (this.me.chatProps.stream) { theResp = await this.handle_response_multipart(resp, apiEP, elDiv); this.latestResponse.clear(); - } catch (error) { - theResp = this.latestResponse; - theResp.ns.role = Roles.Assistant; - this.add(theResp); - this.latestResponse.clear(); - throw error; + } else { + theResp = await this.handle_response_oneshot(resp, apiEP); } - } else { - theResp = await this.handle_response_oneshot(resp, apiEP); + } catch (error) { + theResp = this.latestResponse; + theResp.ns.role = Roles.Assistant; + this.add(theResp); + this.latestResponse.clear(); + throw error; } if (this.me.chatProps.bTrimGarbage) { let origMsg = theResp.ns.getContent();