diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-11-19 11:35:02 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-11-19 11:35:02 +0100 |
commit | 7f1b8c9c602e2337e532fe51df7b4897973ef126 (patch) | |
tree | 25ba9a3371f0094a6601c97aa9d873c2f56bacba /g4f/gui | |
parent | Add image upload to Copilot provider (diff) | |
download | gpt4free-7f1b8c9c602e2337e532fe51df7b4897973ef126.tar gpt4free-7f1b8c9c602e2337e532fe51df7b4897973ef126.tar.gz gpt4free-7f1b8c9c602e2337e532fe51df7b4897973ef126.tar.bz2 gpt4free-7f1b8c9c602e2337e532fe51df7b4897973ef126.tar.lz gpt4free-7f1b8c9c602e2337e532fe51df7b4897973ef126.tar.xz gpt4free-7f1b8c9c602e2337e532fe51df7b4897973ef126.tar.zst gpt4free-7f1b8c9c602e2337e532fe51df7b4897973ef126.zip |
Diffstat (limited to 'g4f/gui')
-rw-r--r-- | g4f/gui/client/static/js/chat.v1.js | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 11306cdc..9f6103fb 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -25,7 +25,8 @@ const optionElements = document.querySelectorAll(".settings input, .settings tex let provider_storage = {}; let message_storage = {}; let controller_storage = {}; -let content_storage = {} +let content_storage = {}; +let error_storage = {}; messageInput.addEventListener("blur", () => { window.scrollTo(0, 0); @@ -256,14 +257,14 @@ const delete_conversations = async () => { const handle_ask = async () => { messageInput.style.height = "82px"; messageInput.focus(); - window.scrollTo(0, 0); + await scroll_to_bottom(); let message = messageInput.value; if (message.length <= 0) { return; } messageInput.value = ""; - count_input() + await count_input() await add_conversation(window.conversation_id, message); if ("text" in fileInput.dataset) { @@ -396,7 +397,7 @@ async function add_message_chunk(message, message_index) { } else if (message.type == "message") { console.error(message.message) } else if (message.type == "error") { - window.error = message.error + error_storage[message_index] = message.error console.error(message.error); content_map.inner.innerHTML += `<p><strong>An error occured:</strong> ${message.error}</p>`; } else if (message.type == "preview") { @@ -469,7 +470,6 @@ const ask_gpt = async (message_index = -1, message_id) => { `; controller_storage[message_index] = new AbortController(); - let error = false; let content_el = document.getElementById(`gpt_${message_id}`) let content_map = content_storage[message_index] = { @@ -478,8 +478,7 @@ const ask_gpt = async (message_index = -1, message_id) => { count: content_el.querySelector('.count'), } - message_box.scrollTop = message_box.scrollHeight; - window.scrollTo(0, 0); + await scroll_to_bottom(); try { const input = imageInput && imageInput.files.length > 0 ? imageInput : cameraInput; const file = input && input.files.length > 0 ? input.files[0] : null; @@ -501,7 +500,7 @@ const ask_gpt = async (message_index = -1, message_id) => { auto_continue: auto_continue, api_key: api_key }, file, message_index); - if (!error) { + if (!error_storage[message_index]) { html = markdown_render(message_storage[message_index]); content_map.inner.innerHTML = html; highlight(content_map.inner); @@ -513,7 +512,7 @@ const ask_gpt = async (message_index = -1, message_id) => { } catch (e) { console.error(e); if (e.name != "AbortError") { - error = true; + error_storage[message_index] = true; content_map.inner.innerHTML += `<p><strong>An error occured:</strong> ${e}</p>`; } } @@ -526,13 +525,18 @@ const ask_gpt = async (message_index = -1, message_id) => { let cursorDiv = message_box.querySelector(".cursor"); if (cursorDiv) cursorDiv.parentNode.removeChild(cursorDiv); } - window.scrollTo(0, 0); - message_box.scrollTop = message_box.scrollHeight; + await scroll_to_bottom(); await remove_cancel_button(); await register_message_buttons(); await load_conversations(); + regenerate.classList.remove("regenerate-hidden"); }; +async function scroll_to_bottom() { + window.scrollTo(0, 0); + message_box.scrollTop = message_box.scrollHeight; +} + const clear_conversations = async () => { const elements = box_conversations.childNodes; let index = elements.length; |