diff --git a/api_webchat/model-worker-ollama.js b/api_webchat/model-worker-ollama.js index f8c0c0fb..9d66b757 100644 --- a/api_webchat/model-worker-ollama.js +++ b/api_webchat/model-worker-ollama.js @@ -65,9 +65,11 @@ self.onmessage = async function(event) { while (true) { if (stopStreaming) { stopStreaming = false; + reader.cancel(); conversationHistory.push({ role: 'assistant', content: assistantResponseAccumulator }); assistantResponseAccumulator = ''; postMessage({ type: 'tokensDone' }); + break; } const { done, value } = await reader.read(); diff --git a/api_webchat/model-worker-openai.js b/api_webchat/model-worker-openai.js index a8f041d5..de9ba27c 100644 --- a/api_webchat/model-worker-openai.js +++ b/api_webchat/model-worker-openai.js @@ -110,6 +110,7 @@ self.onmessage = async function(event) { while (true) { if (stopStreaming) { stopStreaming = false; + reader.cancel(); conversationHistory.push({ role: 'assistant', content: assistantResponseAccumulator }); assistantResponseAccumulator = ''; postMessage({ type: 'tokensDone' });