summaryrefslogtreecommitdiffstats
path: root/g4f/gui
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-03 16:02:06 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-03 16:02:06 +0100
commit25895eb63799a1c38a40f03a48e85cdd8e9dc4b9 (patch)
tree2e1a35054f01c91298993c777b7756cdd9d7bae9 /g4f/gui
parentNew Provider 'Bestim' (#1416) (diff)
downloadgpt4free-25895eb63799a1c38a40f03a48e85cdd8e9dc4b9.tar
gpt4free-25895eb63799a1c38a40f03a48e85cdd8e9dc4b9.tar.gz
gpt4free-25895eb63799a1c38a40f03a48e85cdd8e9dc4b9.tar.bz2
gpt4free-25895eb63799a1c38a40f03a48e85cdd8e9dc4b9.tar.lz
gpt4free-25895eb63799a1c38a40f03a48e85cdd8e9dc4b9.tar.xz
gpt4free-25895eb63799a1c38a40f03a48e85cdd8e9dc4b9.tar.zst
gpt4free-25895eb63799a1c38a40f03a48e85cdd8e9dc4b9.zip
Diffstat (limited to 'g4f/gui')
-rw-r--r--g4f/gui/client/html/index.html5
-rw-r--r--g4f/gui/client/js/chat.v1.js26
-rw-r--r--g4f/gui/server/backend.py13
3 files changed, 35 insertions, 9 deletions
diff --git a/g4f/gui/client/html/index.html b/g4f/gui/client/html/index.html
index da7aeefb..b47f2a37 100644
--- a/g4f/gui/client/html/index.html
+++ b/g4f/gui/client/html/index.html
@@ -125,6 +125,11 @@
<span class="about">Web Access</span>
</div>
<div class="field">
+ <input type="checkbox" id="patch" />
+ <label for="patch" title="Works only with Bing and some other providers"></label>
+ <span class="about">Image Generator</span>
+ </div>
+ <div class="field">
<select name="model" id="model">
<option value="gpt-3.5-turbo" selected="">gpt-3.5-turbo</option>
<option value="gpt-3.5-turbo-0613">gpt-3.5-turbo-0613</option>
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)) {
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py
index 595f5aa1..00f2a827 100644
--- a/g4f/gui/server/backend.py
+++ b/g4f/gui/server/backend.py
@@ -6,9 +6,14 @@ import json
from flask import request, Flask
from .internet import get_search_message
from g4f import debug, version
-
+from g4f.base_provider import ProviderType
debug.logging = True
+def patch_provider(provider: ProviderType):
+ from g4f.Provider import CreateImagesProvider
+ from g4f.Provider.bing.create_images import create_completion
+ return CreateImagesProvider(provider, create_completion)
+
class Backend_Api:
def __init__(self, app: Flask) -> None:
self.app: Flask = app
@@ -72,7 +77,8 @@ class Backend_Api:
model = model if model else g4f.models.default
provider = request.json.get('provider', '').replace('g4f.Provider.', '')
provider = provider if provider and provider != "Auto" else None
-
+ patch = patch_provider if request.json.get('patch_provider') else None
+
def try_response():
try:
first = True
@@ -81,7 +87,8 @@ class Backend_Api:
provider=provider,
messages=messages,
stream=True,
- ignore_stream_and_auth=True
+ ignore_stream_and_auth=True,
+ patch_provider=patch
):
if first:
first = False