From d4ab83a45bfef2910936dcabf3f875268631e65b Mon Sep 17 00:00:00 2001
From: abc <98614666+xtekky@users.noreply.github.com>
Date: Thu, 19 Oct 2023 15:14:48 +0100
Subject: ~
automatic models fetching in GUI.
---
g4f/gui/client/js/chat.v2.js | 107 +++++++++++++++++++++----------------------
1 file changed, 53 insertions(+), 54 deletions(-)
(limited to 'g4f/gui/client/js')
diff --git a/g4f/gui/client/js/chat.v2.js b/g4f/gui/client/js/chat.v2.js
index f052b7e6..03c3a87a 100644
--- a/g4f/gui/client/js/chat.v2.js
+++ b/g4f/gui/client/js/chat.v2.js
@@ -1,13 +1,12 @@
-const query = (obj) => Object.keys(obj).map((k) => encodeURIComponent(k) + "=" + encodeURIComponent(obj[k])).join("&");
-const colorThemes = document.querySelectorAll('[name="theme"]');
-const markdown = window.markdownit();
-const message_box = document.getElementById(`messages`);
-const message_input = document.getElementById(`message-input`);
+const colorThemes = document.querySelectorAll('[name="theme"]');
+const markdown = window.markdownit();
+const message_box = document.getElementById(`messages`);
+const message_input = document.getElementById(`message-input`);
const box_conversations = document.querySelector(`.top`);
-const spinner = box_conversations.querySelector(".spinner");
-const stop_generating = document.querySelector(`.stop_generating`);
-const send_button = document.querySelector(`#send-button`);
-let prompt_lock = false;
+const spinner = box_conversations.querySelector(".spinner");
+const stop_generating = document.querySelector(`.stop_generating`);
+const send_button = document.querySelector(`#send-button`);
+let prompt_lock = false;
hljs.addPlugin(new CopyButtonPlugin());
@@ -81,8 +80,6 @@ const ask_gpt = async (message) => {
`;
- /* .replace(/(?:\r\n|\r|\n)/g, '
') */
-
message_box.scrollTop = message_box.scrollHeight;
window.scrollTo(0, 0);
await new Promise((r) => setTimeout(r, 500));
@@ -108,10 +105,8 @@ const ask_gpt = async (message) => {
method: `POST`,
signal: window.controller.signal,
headers: {
- "content-type": `application/json`,
+ 'content-type': `application/json`,
accept: `text/event-stream`,
- // v: `1.0.0`,
- // ts: Date.now().toString(),
},
body: JSON.stringify({
conversation_id: window.conversation_id,
@@ -123,12 +118,12 @@ const ask_gpt = async (message) => {
id: window.token,
content: {
conversation: await get_conversation(window.conversation_id),
- internet_access: document.getElementById("switch").checked,
- content_type: "text",
+ internet_access: document.getElementById(`switch`).checked,
+ content_type: `text`,
parts: [
{
content: message,
- role: "user",
+ role: `user`,
},
],
},
@@ -146,8 +141,7 @@ const ask_gpt = async (message) => {
text += chunk;
- document.getElementById(`gpt_${window.token}`).innerHTML =
- markdown.render(text);
+ document.getElementById(`gpt_${window.token}`).innerHTML = markdown.render(text);
document.querySelectorAll(`code`).forEach((el) => {
hljs.highlightElement(el);
});
@@ -169,6 +163,7 @@ const ask_gpt = async (message) => {
await load_conversations(20, 0);
window.scrollTo(0, 0);
+
} catch (e) {
add_message(window.conversation_id, "user", message);
@@ -227,19 +222,19 @@ const show_option = async (conversation_id) => {
const yes = document.getElementById(`yes-${conversation_id}`);
const not = document.getElementById(`not-${conversation_id}`);
- conv.style.display = "none";
- yes.style.display = "block";
- not.style.display = "block";
+ conv.style.display = `none`;
+ yes.style.display = `block`;
+ not.style.display = `block`;
};
const hide_option = async (conversation_id) => {
const conv = document.getElementById(`conv-${conversation_id}`);
- const yes = document.getElementById(`yes-${conversation_id}`);
- const not = document.getElementById(`not-${conversation_id}`);
+ const yes = document.getElementById(`yes-${conversation_id}`);
+ const not = document.getElementById(`not-${conversation_id}`);
- conv.style.display = "block";
- yes.style.display = "none";
- not.style.display = "none";
+ conv.style.display = `block`;
+ yes.style.display = `none`;
+ not.style.display = `none`;
};
const delete_conversation = async (conversation_id) => {
@@ -272,7 +267,7 @@ const new_conversation = async () => {
await clear_conversation();
await load_conversations(20, 0, true);
- await make_announcement()
+ await say_hello()
};
const load_conversation = async (conversation_id) => {
@@ -287,15 +282,15 @@ const load_conversation = async (conversation_id) => {