From 5096946b5742a3289ce9ba81047dbb574e67cf86 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 15 Jan 2024 12:52:28 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20ollama=20streaming=20logic?= =?UTF-8?q?=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/llm/llms/Ollama.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index 32615e37f..194da7d55 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -123,6 +123,7 @@ class Ollama extends BaseLLM { buffer += value; // Split the buffer into individual JSON chunks const chunks = buffer.split("\n"); + for (let i = 0; i < chunks.length; i++) { const chunk = chunks[i]; if (chunk.trim() !== "") { @@ -161,6 +162,8 @@ class Ollama extends BaseLLM { buffer += value; // Split the buffer into individual JSON chunks const chunks = buffer.split("\n"); + buffer = chunks.pop() ?? ""; + for (let i = 0; i < chunks.length; i++) { const chunk = chunks[i]; if (chunk.trim() !== "") { @@ -179,8 +182,6 @@ class Ollama extends BaseLLM { } } } - // Assign the last chunk to the buffer - buffer = chunks[chunks.length - 1]; } } }