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 febdadfcb..aa7140d29 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) { @@ -129,6 +130,7 @@ } onMount(async () => { + currentDollarAmount = 0.0; if (!$chatId) { chatId.subscribe(async (value) => { if (!value) { @@ -149,6 +151,7 @@ const initNewChat = async () => { window.history.replaceState(history.state, '', `/`); await chatId.set(''); + currentDollarAmount = 0.0; autoScroll = true;