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; }