summaryrefslogtreecommitdiffstats
path: root/g4f/gui/client/static/js
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-03-19 18:59:42 +0100
committerGitHub <noreply@github.com>2024-03-19 18:59:42 +0100
commit79bc56f36e02a3ccb82c92af58363836ab2affb2 (patch)
tree60b32a4cae7f2921ddbb4e77560ac761164989ca /g4f/gui/client/static/js
parent~ | include /local/models dir on pip (diff)
parentFix Bing key error (diff)
downloadgpt4free-79bc56f36e02a3ccb82c92af58363836ab2affb2.tar
gpt4free-79bc56f36e02a3ccb82c92af58363836ab2affb2.tar.gz
gpt4free-79bc56f36e02a3ccb82c92af58363836ab2affb2.tar.bz2
gpt4free-79bc56f36e02a3ccb82c92af58363836ab2affb2.tar.lz
gpt4free-79bc56f36e02a3ccb82c92af58363836ab2affb2.tar.xz
gpt4free-79bc56f36e02a3ccb82c92af58363836ab2affb2.tar.zst
gpt4free-79bc56f36e02a3ccb82c92af58363836ab2affb2.zip
Diffstat (limited to 'g4f/gui/client/static/js')
-rw-r--r--g4f/gui/client/static/js/chat.v1.js73
1 files changed, 51 insertions, 22 deletions
diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js
index 0da72988..bcef4a78 100644
--- a/g4f/gui/client/static/js/chat.v1.js
+++ b/g4f/gui/client/static/js/chat.v1.js
@@ -211,7 +211,7 @@ async function add_message_chunk(message) {
${message.provider.model ? ' with ' + message.provider.model : ''}
`
} else if (message.type == "message") {
- console.error(messag.message)
+ console.error(message.message)
} else if (message.type == "error") {
window.error = message.error
console.error(message.error);
@@ -240,6 +240,27 @@ async function add_message_chunk(message) {
}
}
+cameraInput?.addEventListener("click", (e) => {
+ if (window?.pywebview) {
+ e.preventDefault();
+ pywebview.api.choose_file();
+ }
+})
+
+cameraInput?.addEventListener("click", (e) => {
+ if (window?.pywebview) {
+ e.preventDefault();
+ pywebview.api.take_picture();
+ }
+})
+
+imageInput?.addEventListener("click", (e) => {
+ if (window?.pywebview) {
+ e.preventDefault();
+ pywebview.api.choose_image();
+ }
+})
+
const ask_gpt = async () => {
regenerate.classList.add(`regenerate-hidden`);
messages = await get_messages(window.conversation_id);
@@ -307,8 +328,7 @@ const ask_gpt = async () => {
console.error(e);
if (e.name != "AbortError") {
error = true;
- text = "oops ! something went wrong, please try again / reload. [stacktrace in console]";
- content_inner.innerHTML = text;
+ content_inner.innerHTML += `<p><strong>An error occured:</strong> ${e}</p>`;
}
}
if (!error && text) {
@@ -592,7 +612,7 @@ document.getElementById("cancelButton").addEventListener("click", async () => {
console.log(`aborted ${window.conversation_id}`);
});
-document.getElementById(`regenerateButton`).addEventListener(`click`, async () => {
+document.getElementById("regenerateButton").addEventListener("click", async () => {
prompt_lock = true;
await hide_last_message(window.conversation_id);
window.token = message_id();
@@ -622,14 +642,20 @@ const message_id = () => {
async function hide_sidebar() {
sidebar.classList.remove("shown");
sidebar_button.classList.remove("rotated");
+ if (window.location.pathname == "/menu/") {
+ history.back();
+ }
}
+window.addEventListener('popstate', hide_sidebar, false);
+
sidebar_button.addEventListener("click", (event) => {
if (sidebar.classList.contains("shown")) {
hide_sidebar();
} else {
sidebar.classList.add("shown");
sidebar_button.classList.add("rotated");
+ history.pushState({}, null, "/menu/");
}
window.scrollTo(0, 0);
});
@@ -817,19 +843,6 @@ async function on_api() {
register_settings_storage();
- versions = await api("version");
- document.title = 'g4f - ' + versions["version"];
- let text = "version ~ "
- if (versions["version"] != versions["latest_version"]) {
- let release_url = 'https://github.com/xtekky/gpt4free/releases/tag/' + versions["latest_version"];
- let title = `New version: ${versions["latest_version"]}`;
- text += `<a href="${release_url}" target="_blank" title="${title}">${versions["version"]}</a> `;
- text += `<i class="fa-solid fa-rotate"></i>`
- } else {
- text += versions["version"];
- }
- document.getElementById("version_text").innerHTML = text
-
models = await api("models");
models.forEach((model) => {
let option = document.createElement("option");
@@ -845,8 +858,24 @@ async function on_api() {
})
await load_provider_models(appStorage.getItem("provider"));
- load_settings_storage()
+ await load_settings_storage()
+}
+
+async function load_version() {
+ const versions = await api("version");
+ document.title = 'g4f - ' + versions["version"];
+ let text = "version ~ "
+ if (versions["version"] != versions["latest_version"]) {
+ let release_url = 'https://github.com/xtekky/gpt4free/releases/tag/' + versions["latest_version"];
+ let title = `New version: ${versions["latest_version"]}`;
+ text += `<a href="${release_url}" target="_blank" title="${title}">${versions["version"]}</a> `;
+ text += `<i class="fa-solid fa-rotate"></i>`
+ } else {
+ text += versions["version"];
+ }
+ document.getElementById("version_text").innerHTML = text
}
+setTimeout(load_version, 5000);
for (const el of [imageInput, cameraInput]) {
el.addEventListener('click', async () => {
@@ -913,13 +942,13 @@ function get_selected_model() {
async function api(ressource, args=null, file=null) {
if (window?.pywebview) {
- if (args) {
+ if (args !== null) {
if (ressource == "models") {
ressource = "provider_models";
}
- return pywebview.api["get_" + ressource](args);
+ return pywebview.api[`get_${ressource}`](args);
}
- return pywebview.api["get_" + ressource]();
+ return pywebview.api[`get_${ressource}`]();
}
if (ressource == "models" && args) {
ressource = `${ressource}/${args}`;
@@ -930,7 +959,7 @@ async function api(ressource, args=null, file=null) {
const headers = {
accept: 'text/event-stream'
}
- if (file) {
+ if (file !== null) {
const formData = new FormData();
formData.append('file', file);
formData.append('json', body);