Add purge chat usage option

This commit is contained in:
Webifi 2023-06-24 19:13:14 -05:00
parent b122dfa3f3
commit 6f91286982
1 changed files with 20 additions and 2 deletions

View File

@ -17,8 +17,8 @@
faEye,
faEyeSlash
} from '@fortawesome/free-solid-svg-icons/index'
import { faSquarePlus as faSquarePlusOutline } from '@fortawesome/free-regular-svg-icons/index'
import { apiKeyStorage, addChatFromJSON, chatsStorage, checkStateChange, clearChats, clearMessages, copyChat, globalStorage, setGlobalSettingValueByKey, showSetChatSettings, pinMainMenu, getChat, deleteChat } from './Storage.svelte'
import { faSquareMinus, faSquarePlus as faSquarePlusOutline } from '@fortawesome/free-regular-svg-icons/index'
import { apiKeyStorage, addChatFromJSON, chatsStorage, checkStateChange, clearChats, clearMessages, copyChat, globalStorage, setGlobalSettingValueByKey, showSetChatSettings, pinMainMenu, getChat, deleteChat, saveChatStore } from './Storage.svelte'
import { exportAsMarkdown, exportChatAsJSON } from './Export.svelte'
import { restartProfile } from './Profiles.svelte'
import { replace } from 'svelte-spa-router'
@ -106,6 +106,21 @@
setGlobalSettingValueByKey('hideSummarized', !$globalStorage.hideSummarized)
}
const clearUsage = () => {
openModal(PromptConfirm, {
title: 'Clear Chat Usage',
message: 'Are you sure you want to clear your token usage stats for the current chat?',
class: 'is-warning',
confirmButtonClass: 'is-warning',
confirmButton: 'Clear Usage',
onConfirm: () => {
const chat = getChat(chatId)
chat.usage = {}
saveChatStore()
}
})
}
</script>
<div class="dropdown {style}" class:is-active={showChatMenu} use:clickOutside={() => { showChatMenu = false }}>
@ -139,6 +154,9 @@
<a href={'#'} class="dropdown-item" class:is-disabled={!chatId} on:click|preventDefault={() => { if (chatId) close(); clearMessages(chatId) }}>
<span class="menu-icon"><Fa icon={faEraser}/></span> Clear Chat Messages
</a>
<a href={'#'} class="dropdown-item" class:is-disabled={!chatId} on:click|preventDefault={() => { if (chatId) close(); clearUsage() }}>
<span class="menu-icon"><Fa icon={faSquareMinus}/></span> Clear Chat Usage
</a>
<hr class="dropdown-divider">
<a href={'#'} class="dropdown-item" class:is-disabled={!chatId} on:click|preventDefault={() => { close(); exportChatAsJSON(chatId) }}>
<span class="menu-icon"><Fa icon={faDownload}/></span> Backup Chat JSON