mirror of https://github.com/xtekky/gpt4free.git
Increase conversation title lenght
This commit is contained in:
parent
65bcc8ae8b
commit
13a09033fb
|
@ -201,6 +201,7 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
.conversations .convo .left {
|
.conversations .convo .left {
|
||||||
|
width: 100%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -226,9 +227,11 @@ body {
|
||||||
.convo-title {
|
.convo-title {
|
||||||
color: var(--colour-3);
|
color: var(--colour-3);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
max-width: 100%;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.convo-title .datetime {
|
.convo-title .datetime {
|
||||||
|
@ -406,7 +409,7 @@ body {
|
||||||
|
|
||||||
.count_total {
|
.count_total {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
padding-left: 100px;
|
padding-left: 25px;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,6 +677,9 @@ select {
|
||||||
.settings .bottom_buttons {
|
.settings .bottom_buttons {
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}
|
||||||
|
.count_total {
|
||||||
|
padding-left: 98px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-box {
|
.input-box {
|
||||||
|
|
|
@ -64,11 +64,13 @@ const highlight = (container) => {
|
||||||
hljs.highlightElement(el);
|
hljs.highlightElement(el);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (window.MathJax) {
|
||||||
typesetPromise = typesetPromise.then(
|
typesetPromise = typesetPromise.then(
|
||||||
() => MathJax.typesetPromise([container])
|
() => MathJax.typesetPromise([container])
|
||||||
).catch(
|
).catch(
|
||||||
(err) => console.log('Typeset failed: ' + err.message)
|
(err) => console.log('Typeset failed: ' + err.message)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const register_message_buttons = async () => {
|
const register_message_buttons = async () => {
|
||||||
|
@ -577,6 +579,7 @@ const load_conversation = async (conversation_id, scroll=true) => {
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (window.GPTTokenizer_cl100k_base) {
|
||||||
const filtered = prepare_messages(messages, false);
|
const filtered = prepare_messages(messages, false);
|
||||||
if (filtered.length > 0) {
|
if (filtered.length > 0) {
|
||||||
last_model = last_model?.startsWith("gpt-4") ? "gpt-4" : "gpt-3.5-turbo"
|
last_model = last_model?.startsWith("gpt-4") ? "gpt-4" : "gpt-3.5-turbo"
|
||||||
|
@ -585,6 +588,7 @@ const load_conversation = async (conversation_id, scroll=true) => {
|
||||||
elements += `<div class="count_total">(${count_total} tokens used)</div>`;
|
elements += `<div class="count_total">(${count_total} tokens used)</div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message_box.innerHTML = elements;
|
message_box.innerHTML = elements;
|
||||||
register_message_buttons();
|
register_message_buttons();
|
||||||
|
@ -616,20 +620,15 @@ async function save_conversation(conversation_id, conversation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function get_messages(conversation_id) {
|
async function get_messages(conversation_id) {
|
||||||
let conversation = await get_conversation(conversation_id);
|
const conversation = await get_conversation(conversation_id);
|
||||||
return conversation?.items || [];
|
return conversation?.items || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function add_conversation(conversation_id, content) {
|
async function add_conversation(conversation_id, content) {
|
||||||
if (content.length > 18) {
|
|
||||||
title = content.substring(0, 18) + '...'
|
|
||||||
} else {
|
|
||||||
title = content + ' '.repeat(20 - content.length)
|
|
||||||
}
|
|
||||||
if (appStorage.getItem(`conversation:${conversation_id}`) == null) {
|
if (appStorage.getItem(`conversation:${conversation_id}`) == null) {
|
||||||
await save_conversation(conversation_id, {
|
await save_conversation(conversation_id, {
|
||||||
id: conversation_id,
|
id: conversation_id,
|
||||||
title: title,
|
title: "",
|
||||||
added: Date.now(),
|
added: Date.now(),
|
||||||
system: systemPrompt?.value,
|
system: systemPrompt?.value,
|
||||||
items: [],
|
items: [],
|
||||||
|
@ -703,13 +702,25 @@ const load_conversations = async () => {
|
||||||
conversations.push(JSON.parse(conversation));
|
conversations.push(JSON.parse(conversation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
conversations.sort((a, b) => (b.updated||0)-(a.updated||0));
|
||||||
|
|
||||||
await clear_conversations();
|
await clear_conversations();
|
||||||
|
|
||||||
conversations.sort((a, b) => (b.updated||0)-(a.updated||0));
|
|
||||||
|
|
||||||
let html = "";
|
let html = "";
|
||||||
conversations.forEach((conversation) => {
|
conversations.forEach((conversation) => {
|
||||||
|
if (conversation?.items.length > 0) {
|
||||||
|
let old_value = conversation.title;
|
||||||
|
let new_value = (conversation.items[0]["content"]).trim();
|
||||||
|
let new_lenght = new_value.indexOf("\n");
|
||||||
|
new_lenght = new_lenght > 200 || new_lenght < 0 ? 200 : new_lenght;
|
||||||
|
conversation.title = new_value.substring(0, new_lenght);
|
||||||
|
if (conversation.title != old_value) {
|
||||||
|
appStorage.setItem(
|
||||||
|
`conversation:${conversation.id}`,
|
||||||
|
JSON.stringify(conversation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
let updated = "";
|
let updated = "";
|
||||||
if (conversation.updated) {
|
if (conversation.updated) {
|
||||||
const date = new Date(conversation.updated);
|
const date = new Date(conversation.updated);
|
||||||
|
@ -915,14 +926,18 @@ colorThemes.forEach((themeOption) => {
|
||||||
|
|
||||||
function count_tokens(model, text) {
|
function count_tokens(model, text) {
|
||||||
if (model) {
|
if (model) {
|
||||||
|
if (window.llamaTokenizer)
|
||||||
if (model.startsWith("llama2") || model.startsWith("codellama")) {
|
if (model.startsWith("llama2") || model.startsWith("codellama")) {
|
||||||
return llamaTokenizer?.encode(text).length;
|
return llamaTokenizer.encode(text).length;
|
||||||
}
|
}
|
||||||
|
if (window.mistralTokenizer)
|
||||||
if (model.startsWith("mistral") || model.startsWith("mixtral")) {
|
if (model.startsWith("mistral") || model.startsWith("mixtral")) {
|
||||||
return mistralTokenizer?.encode(text).length;
|
return mistralTokenizer.encode(text).length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GPTTokenizer_cl100k_base?.encode(text).length;
|
if (window.GPTTokenizer_cl100k_base) {
|
||||||
|
return GPTTokenizer_cl100k_base.encode(text).length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function count_words(text) {
|
function count_words(text) {
|
||||||
|
|
Loading…
Reference in New Issue