summaryrefslogtreecommitdiffstats
path: root/g4f/gui/client/js/chat.v1.js
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-02-26 11:48:56 +0100
committerGitHub <noreply@github.com>2024-02-26 11:48:56 +0100
commitd44238ee1281b43ec4d6f67b4bc1a19be8dc7afb (patch)
tree4cf4452ff58a806bcae4b021f725f4f181998888 /g4f/gui/client/js/chat.v1.js
parentMerge pull request #1634 from xwxtwd/main (diff)
parentFix filter messages in gui (diff)
downloadgpt4free-d44238ee1281b43ec4d6f67b4bc1a19be8dc7afb.tar
gpt4free-d44238ee1281b43ec4d6f67b4bc1a19be8dc7afb.tar.gz
gpt4free-d44238ee1281b43ec4d6f67b4bc1a19be8dc7afb.tar.bz2
gpt4free-d44238ee1281b43ec4d6f67b4bc1a19be8dc7afb.tar.lz
gpt4free-d44238ee1281b43ec4d6f67b4bc1a19be8dc7afb.tar.xz
gpt4free-d44238ee1281b43ec4d6f67b4bc1a19be8dc7afb.tar.zst
gpt4free-d44238ee1281b43ec4d6f67b4bc1a19be8dc7afb.zip
Diffstat (limited to 'g4f/gui/client/js/chat.v1.js')
-rw-r--r--g4f/gui/client/js/chat.v1.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js
index edd27689..8b065be2 100644
--- a/g4f/gui/client/js/chat.v1.js
+++ b/g4f/gui/client/js/chat.v1.js
@@ -123,9 +123,9 @@ const remove_cancel_button = async () => {
const filter_messages = (messages) => {
// Removes none user messages at end
let last_message;
- while (last_message = new_messages.pop()) {
+ while (last_message = messages.pop()) {
if (last_message["role"] == "user") {
- new_messages.push(last_message);
+ messages.push(last_message);
break;
}
}
@@ -430,9 +430,12 @@ const load_conversation = async (conversation_id) => {
`;
}
- let count_total = GPTTokenizer_cl100k_base?.encodeChat(filter_messages(messages), "gpt-3.5-turbo").length
- if (count_total > 0) {
- elements += `<div class="count_total">(${count_total} tokens used)</div>`;
+ const filtered = filter_messages(messages);
+ if (filtered.length > 0) {
+ let count_total = GPTTokenizer_cl100k_base?.encodeChat(filtered, "gpt-3.5-turbo").length
+ if (count_total > 0) {
+ elements += `<div class="count_total">(${count_total} tokens used)</div>`;
+ }
}
message_box.innerHTML = elements;