From 6bfd61f817288079ed9ee876fb0100975f0e6744 Mon Sep 17 00:00:00 2001 From: jimmoffet Date: Fri, 22 Nov 2024 23:06:43 -0800 Subject: [PATCH 1/2] fix costs for new chats --- src/lib/components/chat/Chat.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index febdadfcb..4a712fffb 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -110,6 +110,7 @@ messages = _messages; } else { messages = []; + currentDollarAmount = 0.0; } $: if (chatIdProp) { @@ -149,6 +150,7 @@ const initNewChat = async () => { window.history.replaceState(history.state, '', `/`); await chatId.set(''); + currentDollarAmount = 0.0; autoScroll = true; From 2065ac91b9b2627850235f755d5c430fdcf7489d Mon Sep 17 00:00:00 2001 From: jimmoffet Date: Sat, 23 Nov 2024 11:19:25 -0800 Subject: [PATCH 2/2] fix cost zero on new chat --- src/lib/apis/streaming/index.ts | 10 +++++----- src/lib/components/chat/Chat.svelte | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/apis/streaming/index.ts b/src/lib/apis/streaming/index.ts index 6f152b9d9..94ee2dfe8 100644 --- a/src/lib/apis/streaming/index.ts +++ b/src/lib/apis/streaming/index.ts @@ -56,6 +56,11 @@ async function* openAIStreamToIterator( const data = value.data; try { + if (data.startsWith('[DONE]')) { + yield { done: true, value: '', cost: cost }; + break; + } + const parsedData = JSON.parse(data); // console.log('parsedData', parsedData); @@ -63,11 +68,6 @@ async function* openAIStreamToIterator( cost = parsedData.cost; } - if (data.startsWith('[DONE]')) { - yield { done: true, value: '', cost: cost }; - break; - } - if (parsedData.error) { yield { done: true, value: '', error: parsedData.error, cost: cost }; break; diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 4a712fffb..aa7140d29 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -130,6 +130,7 @@ } onMount(async () => { + currentDollarAmount = 0.0; if (!$chatId) { chatId.subscribe(async (value) => { if (!value) {