From 1ec37aea224938640a4eee7664087d6eb0da6abc Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 2 Mar 2024 17:32:12 +0100 Subject: Fix history on error, fix count words for chinese --- g4f/gui/client/js/chat.v1.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'g4f/gui') diff --git a/g4f/gui/client/js/chat.v1.js b/g4f/gui/client/js/chat.v1.js index ff486c6e..7e1bb397 100644 --- a/g4f/gui/client/js/chat.v1.js +++ b/g4f/gui/client/js/chat.v1.js @@ -466,13 +466,14 @@ const load_conversation = async (conversation_id) => { }, 500); }; -function count_words(text) { - var matches = text.match(/[\w\d\’\'-]+/gi); +// https://stackoverflow.com/questions/20396456/how-to-do-word-counts-for-a-mixture-of-english-and-chinese-in-javascript +function count_words(str) { + var matches = str.match(/[\u00ff-\uffff]|\S+/g); return matches ? matches.length : 0; } function count_tokens(model, text) { - if (model.startsWith("gpt-3") || model.startsWith("gpt-4") || model.startsWith("text-davinci")) { + if (model.startsWith("gpt-3") || model.startsWith("gpt-4")) { return GPTTokenizer_cl100k_base?.encode(text).length; } if (model.startsWith("llama2") || model.startsWith("codellama")) { @@ -524,7 +525,9 @@ const add_conversation = async (conversation_id, content) => { const hide_last_message = async (conversation_id) => { const conversation = await get_conversation(conversation_id) const last_message = conversation.items.pop(); - last_message["regenerate"] = true; + if (last_message["role"] == "assistant") { + last_message["regenerate"] = true; + } conversation.items.push(last_message); localStorage.setItem( -- cgit v1.2.3