diff --git a/src/interface/desktop/chat.html b/src/interface/desktop/chat.html index 34f78951..120f6647 100644 --- a/src/interface/desktop/chat.html +++ b/src/interface/desktop/chat.html @@ -361,12 +361,25 @@ if (newResponseText.getElementsByClassName("spinner").length > 0) { newResponseText.removeChild(loadingSpinner); } + // Try to parse the chunk as a JSON object. It will be a JSON object if there is an error. + if (chunk.startsWith("{") && chunk.endsWith("}")) { + try { + const responseAsJson = JSON.parse(chunk); + if (responseAsJson.detail) { + newResponseText.innerHTML += responseAsJson.detail; + } + } catch (error) { + // If the chunk is not a JSON object, just display it as is + newResponseText.innerHTML += chunk; + } + } else { + // If the chunk is not a JSON object, just display it as is + rawResponse += chunk; + newResponseText.innerHTML = ""; + newResponseText.appendChild(formatHTMLMessage(rawResponse)); - rawResponse += chunk; - newResponseText.innerHTML = ""; - newResponseText.appendChild(formatHTMLMessage(rawResponse)); - - readStream(); + readStream(); + } } // Scroll to bottom of chat window as chat response is streamed diff --git a/src/interface/desktop/config.html b/src/interface/desktop/config.html index fb39fbb8..f8ecb06f 100644 --- a/src/interface/desktop/config.html +++ b/src/interface/desktop/config.html @@ -101,6 +101,9 @@