This commit is contained in:
Webifi 2023-05-28 11:58:48 -05:00
parent 5d7b51ba1d
commit 17d5ee196f
3 changed files with 9 additions and 16 deletions

View File

@ -62,7 +62,7 @@
import { v4 as uuidv4 } from 'uuid'
import { exportChatAsJSON, exportProfileAsJSON } from './Export.svelte'
import { clickOutside } from 'svelte-use-click-outside'
import { getPrice } from './Stats.svelte';
import { getPrice } from './Stats.svelte'
// This makes it possible to override the OpenAI API base URL in the .env file
const apiBase = import.meta.env.VITE_API_BASE || 'https://api.openai.com'
@ -94,7 +94,6 @@
updateChatSettings(chatId)
onMount(async () => {
// Focus the input on mount
focusInput()
@ -782,7 +781,7 @@
</form>
<!-- a target to scroll to -->
<div class="chat-focus-point running-total-container">
{#each Object.entries(chat.usage||{}) as [model, usage]}
{#each Object.entries(chat.usage || {}) as [model, usage]}
<p class="is-size-7 running-totals">
<em>{model}</em> total <span class="has-text-weight-bold">{usage.total_tokens}</span>
tokens ~= <span class="has-text-weight-bold">${getPrice(usage, model).toFixed(6)}</span>

View File

@ -175,12 +175,6 @@
min-width: 100px;
min-height: 30px;
}
a.message-display {
display: block;
text-decoration: none !important;
min-width: 100px;
min-height: 30px;
}
.button-pack {
display: none;
position: absolute;

View File

@ -30,7 +30,7 @@
name: `Chat ${chatId}`,
settings: {} as ChatSettings,
messages: [],
usage:{} as Record<Model,Usage>,
usage: {} as Record<Model, Usage>
})
chatsStorage.set(chats)
// Apply defaults and prepare it to start
@ -83,11 +83,11 @@
})
// Make sure the usage totals object is set
// (some earlier versions of this had different structures)
const hasUsage = chat.usage && !Array.isArray(chat.usage)
&& typeof chat.usage === 'object'
&& Object.values(chat.usage).find(v=>'prompt_tokens' in v)
const hasUsage = chat.usage && !Array.isArray(chat.usage) &&
typeof chat.usage === 'object' &&
Object.values(chat.usage).find(v => 'prompt_tokens' in v)
if (!hasUsage) {
const usageMap:Record<Model,Usage> = {}
const usageMap:Record<Model, Usage> = {}
chat.usage = usageMap
}
chatsStorage.set(chats)
@ -138,8 +138,8 @@
total = {
prompt_tokens: 0,
completion_tokens: 0,
total_tokens: 0,
}
total_tokens: 0
}
chat.usage[model] = total
}
total.completion_tokens += usage.completion_tokens