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

XFEstudio/gpt4free

Increase conversation title lenght

13a09033
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +45 -24
Modified g4f/gui/client/static/css/style.css +7 -1
@@ -201,6 +201,7 @@ body {
201 201 }
202 202
203 203 .conversations .convo .left {
204 width: 100%;
204 205 cursor: pointer;
205 206 display: flex;
206 207 align-items: center;
@@ -226,9 +227,11 @@ body {
226 227 .convo-title {
227 228 color: var(--colour-3);
228 229 font-size: 14px;
230 max-width: 100%;
229 231 text-overflow: ellipsis;
230 232 overflow: hidden;
231 233 white-space: nowrap;
234 margin-right: 10px;
232 235 }
233 236
234 237 .convo-title .datetime {
@@ -406,7 +409,7 @@ body {
406 409
407 410 .count_total {
408 411 font-size: 12px;
409 padding-left: 100px;
412 padding-left: 25px;
410 413 padding-top: 10px;
411 414 }
412 415
@@ -674,6 +677,9 @@ select {
674 677 .settings .bottom_buttons {
675 678 flex-direction: row;
676 679 }
680 .count_total {
681 padding-left: 98px;
682 }
677 683 }
678 684
679 685 .input-box {
Modified g4f/gui/client/static/js/chat.v1.js +38 -23
@@ -64,11 +64,13 @@ const highlight = (container) => {
64 64 hljs.highlightElement(el);
65 65 }
66 66 });
67 typesetPromise = typesetPromise.then(
68 () => MathJax.typesetPromise([container])
69 ).catch(
70 (err) => console.log('Typeset failed: ' + err.message)
71 );
67 if (window.MathJax) {
68 typesetPromise = typesetPromise.then(
69 () => MathJax.typesetPromise([container])
70 ).catch(
71 (err) => console.log('Typeset failed: ' + err.message)
72 );
73 }
72 74 }
73 75
74 76 const register_message_buttons = async () => {
@@ -577,12 +579,14 @@ const load_conversation = async (conversation_id, scroll=true) => {
577 579 `;
578 580 }
579 581
580 const filtered = prepare_messages(messages, false);
581 if (filtered.length > 0) {
582 last_model = last_model?.startsWith("gpt-4") ? "gpt-4" : "gpt-3.5-turbo"
583 let count_total = GPTTokenizer_cl100k_base?.encodeChat(filtered, last_model).length
584 if (count_total > 0) {
585 elements += `<div class="count_total">(${count_total} tokens used)</div>`;
582 if (window.GPTTokenizer_cl100k_base) {
583 const filtered = prepare_messages(messages, false);
584 if (filtered.length > 0) {
585 last_model = last_model?.startsWith("gpt-4") ? "gpt-4" : "gpt-3.5-turbo"
586 let count_total = GPTTokenizer_cl100k_base?.encodeChat(filtered, last_model).length
587 if (count_total > 0) {
588 elements += `<div class="count_total">(${count_total} tokens used)</div>`;
589 }
586 590 }
587 591 }
588 592
@@ -616,20 +620,15 @@ async function save_conversation(conversation_id, conversation) {
616 620 }
617 621
618 622 async function get_messages(conversation_id) {
619 let conversation = await get_conversation(conversation_id);
623 const conversation = await get_conversation(conversation_id);
620 624 return conversation?.items || [];
621 625 }
622 626
623 627 async function add_conversation(conversation_id, content) {
624 if (content.length > 18) {
625 title = content.substring(0, 18) + '...'
626 } else {
627 title = content + '&nbsp;'.repeat(20 - content.length)
628 }
629 628 if (appStorage.getItem(`conversation:${conversation_id}`) == null) {
630 629 await save_conversation(conversation_id, {
631 630 id: conversation_id,
632 title: title,
631 title: "",
633 632 added: Date.now(),
634 633 system: systemPrompt?.value,
635 634 items: [],
@@ -703,13 +702,25 @@ const load_conversations = async () => {
703 702 conversations.push(JSON.parse(conversation));
704 703 }
705 704 }
705 conversations.sort((a, b) => (b.updated||0)-(a.updated||0));
706 706
707 707 await clear_conversations();
708 708
709 conversations.sort((a, b) => (b.updated||0)-(a.updated||0));
710
711 709 let html = "";
712 710 conversations.forEach((conversation) => {
711 if (conversation?.items.length > 0) {
712 let old_value = conversation.title;
713 let new_value = (conversation.items[0]["content"]).trim();
714 let new_lenght = new_value.indexOf("\n");
715 new_lenght = new_lenght > 200 || new_lenght < 0 ? 200 : new_lenght;
716 conversation.title = new_value.substring(0, new_lenght);
717 if (conversation.title != old_value) {
718 appStorage.setItem(
719 `conversation:${conversation.id}`,
720 JSON.stringify(conversation)
721 );
722 }
723 }
713 724 let updated = "";
714 725 if (conversation.updated) {
715 726 const date = new Date(conversation.updated);
@@ -915,14 +926,18 @@ colorThemes.forEach((themeOption) => {
915 926
916 927 function count_tokens(model, text) {
917 928 if (model) {
929 if (window.llamaTokenizer)
918 930 if (model.startsWith("llama2") || model.startsWith("codellama")) {
919 return llamaTokenizer?.encode(text).length;
931 return llamaTokenizer.encode(text).length;
920 932 }
933 if (window.mistralTokenizer)
921 934 if (model.startsWith("mistral") || model.startsWith("mixtral")) {
922 return mistralTokenizer?.encode(text).length;
935 return mistralTokenizer.encode(text).length;
923 936 }
924 937 }
925 return GPTTokenizer_cl100k_base?.encode(text).length;
938 if (window.GPTTokenizer_cl100k_base) {
939 return GPTTokenizer_cl100k_base.encode(text).length;
940 }
926 941 }
927 942
928 943 function count_words(text) {