返回提交历史
Modified
g4f/gui/client/js/chat.v1.js
+1
-8
XFEstudio/gpt4free
Use word word count from alfaaz
e889f3cb
代码差异
1 个文件
+1
-8
@@ -66,7 +66,6 @@ const register_remove_message = async () => {
66
66
}
67
67
68
68
const delete_conversations = async () => {
69
localStorage.clear();
70
69
for (let i = 0; i < localStorage.length; i++){
71
70
let key = localStorage.key(i);
72
71
if (key.startsWith("conversation:")) {
@@ -476,12 +475,6 @@ const load_conversation = async (conversation_id) => {
476
475
}, 500);
477
476
};
478
477
479
// https://stackoverflow.com/questions/20396456/how-to-do-word-counts-for-a-mixture-of-english-and-chinese-in-javascript
480
function count_words(str) {
481
var matches = str.match(/[\u00ff-\uffff]|\S+/g);
482
return matches ? matches.length : 0;
483
}
484
485
478
function count_tokens(model, text) {
486
479
if (model.startsWith("gpt-3") || model.startsWith("gpt-4")) {
487
480
return GPTTokenizer_cl100k_base?.encode(text).length;
@@ -497,7 +490,7 @@ function count_tokens(model, text) {
497
490
function count_words_and_tokens(text, model) {
498
491
const tokens_count = model ? count_tokens(model, text) : null;
499
492
const tokens_append = tokens_count ? `, ${tokens_count} tokens` : "";
500
return `(${count_words(text)} words${tokens_append})`
493
return countWords ? `(${countWords(text)} words${tokens_append})` : "";
501
494
}
502
495
503
496
const get_conversation = async (conversation_id) => {