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.
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

View File

@ -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();