From 46a9d603f4d1e9ea09d54f3500bcf2f94336b670 Mon Sep 17 00:00:00 2001 From: ksanchez Date: Thu, 2 May 2024 23:29:33 -0600 Subject: [PATCH] Add method to get BOS token. --- LLama/LLamaContext.cs | 13 ++++++++++++- LLama/Native/SafeLLamaContextHandle.cs | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/LLama/LLamaContext.cs b/LLama/LLamaContext.cs index 7d0c0f91..4f8e7d94 100644 --- a/LLama/LLamaContext.cs +++ b/LLama/LLamaContext.cs @@ -1,4 +1,4 @@ -using LLama.Exceptions; +using LLama.Exceptions; using LLama.Native; using System; using System.Collections.Generic; @@ -521,6 +521,17 @@ namespace LLama return candidates_p; } + /// + /// Gets whether or not the Bos token should be added. + /// From common.cpp https://github.com/ggerganov/llama.cpp/blob/60325fa56f61c228464c9f065db3aa6a61f2156e/common/common.cpp#L2417 + /// + /// + public bool ShouldAddBosToken() + { + var addBos = NativeApi.llama_add_bos_token(NativeHandle.ModelHandle); + return addBos != -1 ? Convert.ToBoolean(addBos) : NativeHandle.LLamaVocabType == LLamaVocabType.SentencePiece; + } + #region eval overloads /// /// diff --git a/LLama/Native/SafeLLamaContextHandle.cs b/LLama/Native/SafeLLamaContextHandle.cs index 51568769..13a7aa1b 100644 --- a/LLama/Native/SafeLLamaContextHandle.cs +++ b/LLama/Native/SafeLLamaContextHandle.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; @@ -19,6 +19,8 @@ namespace LLama.Native /// public int VocabCount => ThrowIfDisposed().VocabCount; + public LLamaVocabType LLamaVocabType => ThrowIfDisposed().VocabType; + /// /// Total number of tokens in the context ///