From a03fe003de537bf4044ec6ca658bb33cb768c9f4 Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Mon, 23 Oct 2023 16:42:38 +0100 Subject: [PATCH] Fixed decoding of text "accumulating" over time (never properly clearing buffer) --- LLama/LLamaStatelessExecutor.cs | 2 +- LLama/Native/SafeLlamaModelHandle.cs | 4 ---- LLama/StreamingTokenDecoder.cs | 7 ++++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/LLama/LLamaStatelessExecutor.cs b/LLama/LLamaStatelessExecutor.cs index f5cdfb2e..ab1e9bbc 100644 --- a/LLama/LLamaStatelessExecutor.cs +++ b/LLama/LLamaStatelessExecutor.cs @@ -100,7 +100,7 @@ namespace LLama decoder.Add(id); var decoded = decoder.Read(); - yield return decoder.Read(); + yield return decoded; tokens.Clear(); tokens.Add(id); diff --git a/LLama/Native/SafeLlamaModelHandle.cs b/LLama/Native/SafeLlamaModelHandle.cs index 94ddca2d..b93c2b89 100644 --- a/LLama/Native/SafeLlamaModelHandle.cs +++ b/LLama/Native/SafeLlamaModelHandle.cs @@ -1,11 +1,7 @@ using System; -using System.Buffers; using System.Collections.Generic; -using System.Diagnostics; -using System.Runtime.InteropServices; using System.Text; using LLama.Exceptions; -using LLama.Extensions; namespace LLama.Native { diff --git a/LLama/StreamingTokenDecoder.cs b/LLama/StreamingTokenDecoder.cs index fc459199..c5d9683e 100644 --- a/LLama/StreamingTokenDecoder.cs +++ b/LLama/StreamingTokenDecoder.cs @@ -155,7 +155,12 @@ public sealed class StreamingTokenDecoder /// public string Read() { - return string.Join("", _characters); + if (_characters.Count == 0) + return ""; + + var str = string.Join("", _characters); + _characters.Clear(); + return str; } ///