From 21da7342eb7338b13fec14eee74bb781dbf662b9 Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Tue, 7 Mar 2023 15:47:17 +0800 Subject: [PATCH] fix: Object.hasOwn browser compatibility --- src/hooks/useSubmit.ts | 9 +++++++++ src/utils/countTokens.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/hooks/useSubmit.ts b/src/hooks/useSubmit.ts index e33f94a..87aab05 100644 --- a/src/hooks/useSubmit.ts +++ b/src/hooks/useSubmit.ts @@ -53,6 +53,10 @@ const useSubmit = () => { } if (stream) { + if (stream.locked) + throw new Error( + 'Oops, the stream is locked right now. Please try again' + ); const reader = stream.getReader(); let reading = true; while (reading && useStore.getState().generating) { @@ -80,6 +84,11 @@ const useSubmit = () => { setChats(updatedChats); } } + if (useStore.getState().generating) { + reader.cancel('Cancelled by user'); + } else { + reader.cancel('Generation completed'); + } } } catch (e: unknown) { const err = (e as Error).message; diff --git a/src/utils/countTokens.ts b/src/utils/countTokens.ts index cf4c92d..ac5e4af 100644 --- a/src/utils/countTokens.ts +++ b/src/utils/countTokens.ts @@ -50369,7 +50369,7 @@ const bpe_ranks = dictZip(bpe_merges, range(0, bpe_merges.length)); const cache = {}; const bpe = (token) => { - if (Object.hasOwn(cache, token)) { + if (cache.hasOwnProperty(token)) { return cache[token]; } @@ -50397,7 +50397,7 @@ const bpe = (token) => { ) ]; - if (!Object.hasOwn(bpe_ranks, bigram)) { + if (!bpe_ranks.hasOwnProperty(bigram)) { break; }