XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix history on error, fix count words for chinese

1ec37aea
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +7 -4
Modified g4f/gui/client/js/chat.v1.js +7 -4
@@ -466,13 +466,14 @@ const load_conversation = async (conversation_id) => {
466 466 }, 500);
467 467 };
468 468
469 function count_words(text) {
470 var matches = text.match(/[\w\d\’\'-]+/gi);
469 // https://stackoverflow.com/questions/20396456/how-to-do-word-counts-for-a-mixture-of-english-and-chinese-in-javascript
470 function count_words(str) {
471 var matches = str.match(/[\u00ff-\uffff]|\S+/g);
471 472 return matches ? matches.length : 0;
472 473 }
473 474
474 475 function count_tokens(model, text) {
475 if (model.startsWith("gpt-3") || model.startsWith("gpt-4") || model.startsWith("text-davinci")) {
476 if (model.startsWith("gpt-3") || model.startsWith("gpt-4")) {
476 477 return GPTTokenizer_cl100k_base?.encode(text).length;
477 478 }
478 479 if (model.startsWith("llama2") || model.startsWith("codellama")) {
@@ -524,7 +525,9 @@ const add_conversation = async (conversation_id, content) => {
524 525 const hide_last_message = async (conversation_id) => {
525 526 const conversation = await get_conversation(conversation_id)
526 527 const last_message = conversation.items.pop();
527 last_message["regenerate"] = true;
528 if (last_message["role"] == "assistant") {
529 last_message["regenerate"] = true;
530 }
528 531 conversation.items.push(last_message);
529 532
530 533 localStorage.setItem(