From c66927f472d14c5b9917b12ceb003e3bca66b916 Mon Sep 17 00:00:00 2001 From: mic Date: Thu, 22 Aug 2024 22:42:02 +0200 Subject: [PATCH] really closing the connection to the server when stopped by the user. --- api_webchat/model-worker-ollama.js | 2 ++ api_webchat/model-worker-openai.js | 1 + 2 files changed, 3 insertions(+) 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' });