Increase conversation title lenght

This commit is contained in:
Heiner Lohaus 2024-04-10 15:44:51 +02:00
parent 65bcc8ae8b
commit 13a09033fb
2 changed files with 45 additions and 24 deletions

View File

@ -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 {

View File

@ -64,11 +64,13 @@ const highlight = (container) => {
hljs.highlightElement(el); hljs.highlightElement(el);
} }
}); });
typesetPromise = typesetPromise.then( if (window.MathJax) {
() => MathJax.typesetPromise([container]) typesetPromise = typesetPromise.then(
).catch( () => MathJax.typesetPromise([container])
(err) => console.log('Typeset failed: ' + err.message) ).catch(
); (err) => console.log('Typeset failed: ' + err.message)
);
}
} }
const register_message_buttons = async () => { const register_message_buttons = async () => {
@ -577,12 +579,14 @@ const load_conversation = async (conversation_id, scroll=true) => {
`; `;
} }
const filtered = prepare_messages(messages, false); if (window.GPTTokenizer_cl100k_base) {
if (filtered.length > 0) { const filtered = prepare_messages(messages, false);
last_model = last_model?.startsWith("gpt-4") ? "gpt-4" : "gpt-3.5-turbo" if (filtered.length > 0) {
let count_total = GPTTokenizer_cl100k_base?.encodeChat(filtered, last_model).length last_model = last_model?.startsWith("gpt-4") ? "gpt-4" : "gpt-3.5-turbo"
if (count_total > 0) { let count_total = GPTTokenizer_cl100k_base?.encodeChat(filtered, last_model).length
elements += `<div class="count_total">(${count_total} tokens used)</div>`; if (count_total > 0) {
elements += `<div class="count_total">(${count_total} tokens used)</div>`;
}
} }
} }
@ -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 + '&nbsp;'.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) {