Skip to content

Utils

Namespace: LLama

Assorted llama utilities

public static class Utils

Inheritance ObjectUtils

Methods

InitLLamaContextFromModelParams(IModelParams)

Caution

Use LLamaWeights.LoadFromFile and LLamaWeights.CreateContext instead


public static SafeLLamaContextHandle InitLLamaContextFromModelParams(IModelParams params)

Parameters

params IModelParams

Returns

SafeLLamaContextHandle

Tokenize(SafeLLamaContextHandle, String, Boolean, Encoding)

Caution

Use SafeLLamaContextHandle Tokenize method instead


public static IEnumerable<int> Tokenize(SafeLLamaContextHandle ctx, string text, bool add_bos, Encoding encoding)

Parameters

ctx SafeLLamaContextHandle

text String

add_bos Boolean

encoding Encoding

Returns

IEnumerable<Int32>

GetLogits(SafeLLamaContextHandle, Int32)

Caution

Use SafeLLamaContextHandle GetLogits method instead


public static Span<float> GetLogits(SafeLLamaContextHandle ctx, int length)

Parameters

ctx SafeLLamaContextHandle

length Int32

Returns

Span<Single>

Eval(SafeLLamaContextHandle, Int32[], Int32, Int32, Int32, Int32)

Caution

Use SafeLLamaContextHandle Eval method instead


public static int Eval(SafeLLamaContextHandle ctx, Int32[] tokens, int startIndex, int n_tokens, int n_past, int n_threads)

Parameters

ctx SafeLLamaContextHandle

tokens Int32[]

startIndex Int32

n_tokens Int32

n_past Int32

n_threads Int32

Returns

Int32

TokenToString(Int32, SafeLLamaContextHandle, Encoding)

Caution

Use SafeLLamaContextHandle TokenToString method instead


public static string TokenToString(int token, SafeLLamaContextHandle ctx, Encoding encoding)

Parameters

token Int32

ctx SafeLLamaContextHandle

encoding Encoding

Returns

String

PtrToString(IntPtr, Encoding)

Caution

No longer used internally by LlamaSharp


public static string PtrToString(IntPtr ptr, Encoding encoding)

Parameters

ptr IntPtr

encoding Encoding

Returns

String