summaryrefslogtreecommitdiffstats
path: root/g4f/gui
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-02 17:32:12 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-03-02 17:32:12 +0100
commit1ec37aea224938640a4eee7664087d6eb0da6abc (patch)
treeda74145b6ed48e62e341b2ee00ac771217626733 /g4f/gui
parentMerge pull request #1642 from hlohaus/flow (diff)
downloadgpt4free-1ec37aea224938640a4eee7664087d6eb0da6abc.tar
gpt4free-1ec37aea224938640a4eee7664087d6eb0da6abc.tar.gz
gpt4free-1ec37aea224938640a4eee7664087d6eb0da6abc.tar.bz2
gpt4free-1ec37aea224938640a4eee7664087d6eb0da6abc.tar.lz
gpt4free-1ec37aea224938640a4eee7664087d6eb0da6abc.tar.xz
gpt4free-1ec37aea224938640a4eee7664087d6eb0da6abc.tar.zst
gpt4free-1ec37aea224938640a4eee7664087d6eb0da6abc.zip
Diffstat (limited to '')
-rw-r--r--g4f/gui/client/js/chat.v1.js11
1 files changed, 7 insertions, 4 deletions
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(