summaryrefslogtreecommitdiffstats
path: root/g4f/gui/client/static/js/chat.v1.js
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-11 02:40:30 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-11 02:40:30 +0200
commit009a67239a1df546fd22933a6b28eda03cd02a00 (patch)
tree6428fc06fe339e1c7cb197594dcb7399979a2e19 /g4f/gui/client/static/js/chat.v1.js
parentIncrease conversation title lenght (diff)
downloadgpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.gz
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.bz2
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.lz
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.xz
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.tar.zst
gpt4free-009a67239a1df546fd22933a6b28eda03cd02a00.zip
Diffstat (limited to '')
-rw-r--r--g4f/gui/client/static/js/chat.v1.js44
1 files changed, 20 insertions, 24 deletions
diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js
index d07ca4ea..fd58be6d 100644
--- a/g4f/gui/client/static/js/chat.v1.js
+++ b/g4f/gui/client/static/js/chat.v1.js
@@ -179,12 +179,14 @@ const register_message_buttons = async () => {
}
const delete_conversations = async () => {
+ const remove_keys = [];
for (let i = 0; i < appStorage.length; i++){
let key = appStorage.key(i);
if (key.startsWith("conversation:")) {
- appStorage.removeItem(key);
+ remove_keys.push(key);
}
}
+ remove_keys.forEach((key)=>appStorage.removeItem(key));
hide_sidebar();
await new_conversation();
};
@@ -274,31 +276,21 @@ const prepare_messages = (messages, filter_last_message=true) => {
}
let new_messages = [];
- if (messages) {
- for (i in messages) {
- new_message = messages[i];
- // Remove generated images from history
- new_message.content = new_message.content.replaceAll(
- /<!-- generated images start -->[\s\S]+<!-- generated images end -->/gm,
- ""
- )
- delete new_message["provider"];
- // Remove regenerated messages
- if (!new_message.regenerate) {
- new_messages.push(new_message)
- }
- }
- }
-
- // Add system message
- system_content = systemPrompt?.value;
- if (system_content) {
- new_messages.unshift({
+ if (systemPrompt?.value) {
+ new_messages.push({
"role": "system",
- "content": system_content
+ "content": systemPrompt.value
});
}
-
+ messages.forEach((new_message) => {
+ // Include only not regenerated messages
+ if (!new_message.regenerate) {
+ // Remove generated images from history
+ new_message.content = filter_message(new_message.content);
+ delete new_message.provider;
+ new_messages.push(new_message)
+ }
+ });
return new_messages;
}
@@ -413,8 +405,11 @@ const ask_gpt = async () => {
if (file && !provider)
provider = "Bing";
let api_key = null;
- if (provider)
+ if (provider) {
api_key = document.getElementById(`${provider}-api_key`)?.value || null;
+ if (api_key == null)
+ api_key = document.querySelector(`.${provider}-api_key`)?.value || null;
+ }
await api("conversation", {
id: window.token,
conversation_id: window.conversation_id,
@@ -949,6 +944,7 @@ function count_chars(text) {
}
function count_words_and_tokens(text, model) {
+ text = filter_message(text);
return `(${count_words(text)} words, ${count_chars(text)} chars, ${count_tokens(model, text)} tokens)`;
}