From 84b3a19c9de9168f9eaf769f63e19d30c66f3ddd Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 25 Feb 2024 10:03:27 +0100 Subject: Improve show result in gui --- g4f/gui/client/js/chat.v1.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'g4f/gui/client/js') diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js index 9585ca98..e5b2d653 100644 --- a/g4f/gui/client/js/chat.v1.js +++ b/g4f/gui/client/js/chat.v1.js @@ -268,6 +268,11 @@ const ask_gpt = async () => { } } if (!error) { + // Remove cursor + html = markdown_render(text); + content_inner.innerHTML = html; + highlight(content_inner); + if (imageInput) imageInput.value = ""; if (cameraInput) cameraInput.value = ""; if (fileInput) fileInput.value = ""; @@ -275,20 +280,19 @@ const ask_gpt = async () => { } catch (e) { console.error(e); - if (e.name != `AbortError`) { - text = `oops ! something went wrong, please try again / reload. [stacktrace in console]`; + if (e.name != "AbortError") { + error = true; + text = "oops ! something went wrong, please try again / reload. [stacktrace in console]"; content_inner.innerHTML = text; } else { content_inner.innerHTML += ` [aborted]`; text += ` [aborted]` } } - let cursorDiv = document.getElementById(`cursor`); - if (cursorDiv) cursorDiv.parentNode.removeChild(cursorDiv); - if (text) { + if (!error) { await add_message(window.conversation_id, "assistant", text, provider); + await load_conversation(window.conversation_id); } - await load_conversation(window.conversation_id); message_box.scrollTop = message_box.scrollHeight; await remove_cancel_button(); await register_remove_message(); -- cgit v1.2.3