From 596d51184a8354b2c7f6060c45418fde10109daa Mon Sep 17 00:00:00 2001 From: Jacob Mink Date: Fri, 6 Jun 2025 09:25:09 -0500 Subject: [PATCH] Add DecodeSpecialTokens property to IInferenceParams - implement it where applicable. Use the new property in StatelessExecutor --- LLama.Web/Common/InferenceOptions.cs | 3 +++ LLama/Abstractions/IInferenceParams.cs | 8 ++++++++ LLama/Common/InferenceParams.cs | 3 +++ LLama/LLamaStatelessExecutor.cs | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/LLama.Web/Common/InferenceOptions.cs b/LLama.Web/Common/InferenceOptions.cs index c49d3aa31..1b32a996c 100644 --- a/LLama.Web/Common/InferenceOptions.cs +++ b/LLama.Web/Common/InferenceOptions.cs @@ -21,5 +21,8 @@ public class InferenceOptions /// public ISamplingPipeline SamplingPipeline { get; set; } = new DefaultSamplingPipeline(); + + /// + public bool DecodeSpecialTokens { get; set; } } } diff --git a/LLama/Abstractions/IInferenceParams.cs b/LLama/Abstractions/IInferenceParams.cs index fe415efed..12a335d08 100644 --- a/LLama/Abstractions/IInferenceParams.cs +++ b/LLama/Abstractions/IInferenceParams.cs @@ -28,5 +28,13 @@ public interface IInferenceParams /// Set a custom sampling pipeline to use. /// ISamplingPipeline SamplingPipeline { get; set; } + + /// + /// If true, special characters will be converted to text. If false they will be invisible. + /// + /// + /// Controls the behavior of decoders like + /// + public bool DecodeSpecialTokens { get; set; } } } \ No newline at end of file diff --git a/LLama/Common/InferenceParams.cs b/LLama/Common/InferenceParams.cs index 8f2a5a14f..aa923bf8f 100644 --- a/LLama/Common/InferenceParams.cs +++ b/LLama/Common/InferenceParams.cs @@ -30,6 +30,9 @@ public record InferenceParams /// public ISamplingPipeline SamplingPipeline { get; set; } = new DefaultSamplingPipeline(); + + /// + public bool DecodeSpecialTokens { get; set; } } /// diff --git a/LLama/LLamaStatelessExecutor.cs b/LLama/LLamaStatelessExecutor.cs index 8aa705062..817738895 100644 --- a/LLama/LLamaStatelessExecutor.cs +++ b/LLama/LLamaStatelessExecutor.cs @@ -88,7 +88,10 @@ public async IAsyncEnumerable InferAsync(string prompt, IInferenceParams throw new ArgumentOutOfRangeException(nameof(inferenceParams), $"TokensKeep ({inferenceParams.TokensKeep}) cannot be larger than ContextSize ({Context.ContextSize})"); // Create decoders for the token stream - var decoder = new StreamingTokenDecoder(Context); + var decoder = new StreamingTokenDecoder(Context) + { + DecodeSpecialTokens = inferenceParams.DecodeSpecialTokens, + }; var antiprocessor = new AntipromptProcessor(inferenceParams.AntiPrompts); if (ApplyTemplate)