Browse Source

Add method to get BOS token.

pull/714/head
ksanchez 1 year ago
parent
commit
46a9d603f4
2 changed files with 15 additions and 2 deletions
  1. +12
    -1
      LLama/LLamaContext.cs
  2. +3
    -1
      LLama/Native/SafeLLamaContextHandle.cs

+ 12
- 1
LLama/LLamaContext.cs View File

@@ -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;
}

/// <summary>
/// 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
/// </summary>
/// <returns></returns>
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
/// <summary>
/// </summary>


+ 3
- 1
LLama/Native/SafeLLamaContextHandle.cs View File

@@ -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
/// </summary>
public int VocabCount => ThrowIfDisposed().VocabCount;

public LLamaVocabType LLamaVocabType => ThrowIfDisposed().VocabType;

/// <summary>
/// Total number of tokens in the context
/// </summary>


Loading…
Cancel
Save