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.
This commit is contained in:
hanishkvc 2025-11-12 23:28:47 +05:30
parent 18b94482c5
commit a2a0a378a9
2 changed files with 27 additions and 12 deletions

View File

@ -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. 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 Have unique id or use the index into chat messages array wrt each chat message in a chat session, so that
space by browsers. 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 ### Debuging the handshake and beyond

View File

@ -303,6 +303,16 @@ class ChatMessageEx {
delete(this.ns[key]) 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. * Update based on the drip by drip data got from network in streaming mode.
* Tries to support both Chat and Completion endpoints * Tries to support both Chat and Completion endpoints
@ -311,6 +321,7 @@ class ChatMessageEx {
*/ */
update_stream(nwo, apiEP) { update_stream(nwo, apiEP) {
console.debug(nwo, apiEP) console.debug(nwo, apiEP)
this.update_checkerror(nwo)
if (apiEP == ApiEP.Type.Chat) { if (apiEP == ApiEP.Type.Chat) {
if (nwo["choices"][0]["finish_reason"] === null) { if (nwo["choices"][0]["finish_reason"] === null) {
let content = nwo["choices"][0]["delta"]["content"]; let content = nwo["choices"][0]["delta"]["content"];
@ -363,6 +374,7 @@ class ChatMessageEx {
* @param {string} apiEP * @param {string} apiEP
*/ */
update_oneshot(nwo, apiEP) { update_oneshot(nwo, apiEP) {
this.update_checkerror(nwo)
if (apiEP == ApiEP.Type.Chat) { if (apiEP == ApiEP.Type.Chat) {
let curContent = nwo["choices"][0]["message"]["content"]; let curContent = nwo["choices"][0]["message"]["content"];
if (curContent != undefined) { if (curContent != undefined) {
@ -853,19 +865,19 @@ class SimpleChat {
*/ */
async handle_response(resp, apiEP, elDiv) { async handle_response(resp, apiEP, elDiv) {
let theResp = null; let theResp = null;
if (this.me.chatProps.stream) { try {
try { if (this.me.chatProps.stream) {
theResp = await this.handle_response_multipart(resp, apiEP, elDiv); theResp = await this.handle_response_multipart(resp, apiEP, elDiv);
this.latestResponse.clear(); this.latestResponse.clear();
} catch (error) { } else {
theResp = this.latestResponse; theResp = await this.handle_response_oneshot(resp, apiEP);
theResp.ns.role = Roles.Assistant;
this.add(theResp);
this.latestResponse.clear();
throw error;
} }
} else { } catch (error) {
theResp = await this.handle_response_oneshot(resp, apiEP); theResp = this.latestResponse;
theResp.ns.role = Roles.Assistant;
this.add(theResp);
this.latestResponse.clear();
throw error;
} }
if (this.me.chatProps.bTrimGarbage) { if (this.me.chatProps.bTrimGarbage) {
let origMsg = theResp.ns.getContent(); let origMsg = theResp.ns.getContent();