summaryrefslogtreecommitdiffstats
path: root/g4f/gui/client/js
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-10 10:34:56 +0100
committerGitHub <noreply@github.com>2024-01-10 10:34:56 +0100
commitbee75be8e38d25c4568c641412a49b576d425b24 (patch)
tree63ea1505dbe2b84c3011164a7b2699e642d94c19 /g4f/gui/client/js
parentMerge pull request #1441 from w453y/patch-1 (diff)
downloadgpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.gz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.bz2
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.lz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.xz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.zst
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.zip
Diffstat (limited to '')
-rw-r--r--g4f/gui/client/js/chat.v1.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js
index a335a3cc..9d49d24e 100644
--- a/g4f/gui/client/js/chat.v1.js
+++ b/g4f/gui/client/js/chat.v1.js
@@ -20,7 +20,10 @@ message_input.addEventListener("focus", () => {
});
const markdown_render = (content) => {
- return markdown.render(content)
+ return markdown.render(content
+ .replaceAll(/<!--.+-->/gm, "")
+ .replaceAll(/<img data-prompt="[^>]+">/gm, "")
+ )
.replaceAll("<a href=", '<a target="_blank" href=')
.replaceAll('<code>', '<code class="language-plaintext">')
}
@@ -68,6 +71,15 @@ const ask_gpt = async () => {
regenerate.classList.add(`regenerate-hidden`);
messages = await get_messages(window.conversation_id);
+ // Remove generated images from history
+ for (i in messages) {
+ messages[i]["content"] = messages[i]["content"].replace(
+ /<!-- generated images start -->[\s\S]+<!-- generated images end -->/m,
+ ""
+ )
+ delete messages[i]["provider"];
+ }
+
window.scrollTo(0, 0);
window.controller = new AbortController();
@@ -91,7 +103,8 @@ const ask_gpt = async () => {
</div>
<div class="content" id="gpt_${window.token}">
<div class="provider"></div>
- <div class="content_inner"><div id="cursor"></div></div>
+ <div class="content_inner"></div>
+ <div id="cursor"></div>
</div>
</div>
`;
@@ -115,6 +128,7 @@ const ask_gpt = async () => {
jailbreak: jailbreak.options[jailbreak.selectedIndex].value,
internet_access: document.getElementById(`switch`).checked,
provider: provider.options[provider.selectedIndex].value,
+ patch_provider: document.getElementById('patch').checked,
meta: {
id: window.token,
content: {
@@ -163,8 +177,6 @@ const ask_gpt = async () => {
} catch (e) {
console.log(e);
- let cursorDiv = document.getElementById(`cursor`);
- if (cursorDiv) cursorDiv.parentNode.removeChild(cursorDiv);
if (e.name != `AbortError`) {
text = `oops ! something went wrong, please try again / reload. [stacktrace in console]`;
@@ -174,6 +186,8 @@ const ask_gpt = async () => {
text += ` [aborted]`
}
}
+ let cursorDiv = document.getElementById(`cursor`);
+ if (cursorDiv) cursorDiv.parentNode.removeChild(cursorDiv);
add_message(window.conversation_id, "assistant", text, provider);
message_box.scrollTop = message_box.scrollHeight;
await remove_cancel_button();
@@ -430,7 +444,7 @@ document.querySelector(".mobile-sidebar").addEventListener("click", (event) => {
});
const register_settings_localstorage = async () => {
- settings_ids = ["switch", "model", "jailbreak"];
+ settings_ids = ["switch", "model", "jailbreak", "patch", "provider"];
settings_elements = settings_ids.map((id) => document.getElementById(id));
settings_elements.map((element) =>
element.addEventListener(`change`, async (event) => {
@@ -449,7 +463,7 @@ const register_settings_localstorage = async () => {
};
const load_settings_localstorage = async () => {
- settings_ids = ["switch", "model", "jailbreak"];
+ settings_ids = ["switch", "model", "jailbreak", "patch", "provider"];
settings_elements = settings_ids.map((id) => document.getElementById(id));
settings_elements.map((element) => {
if (localStorage.getItem(element.id)) {