# LLamaModel Namespace: LLama The abstraction of a LLama model, which holds the context in the native library. ```csharp public class LLamaModel : System.IDisposable ``` Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [LLamaModel](./llama.llamamodel.md)
Implements [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable) ## Properties ### **ContextSize** The context size. ```csharp public int ContextSize { get; } ``` #### Property Value [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
### **Params** The model params set for this model. ```csharp public ModelParams Params { get; set; } ``` #### Property Value [ModelParams](./llama.common.modelparams.md)
### **NativeHandle** The native handle, which is used to be passed to the native APIs. Please avoid using it unless you know what is the usage of the Native API. ```csharp public SafeLLamaContextHandle NativeHandle { get; } ``` #### Property Value [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)
### **Encoding** The encoding set for this model to deal with text input. ```csharp public Encoding Encoding { get; } ``` #### Property Value [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)
## Constructors ### **LLamaModel(ModelParams, String, ILLamaLogger)** ```csharp public LLamaModel(ModelParams Params, string encoding, ILLamaLogger logger) ``` #### Parameters `Params` [ModelParams](./llama.common.modelparams.md)
Model params. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
Encoding to deal with text input. `logger` [ILLamaLogger](./llama.common.illamalogger.md)
The logger. ## Methods ### **Tokenize(String, Boolean)** Tokenize a string. ```csharp public IEnumerable Tokenize(string text, bool addBos) ``` #### Parameters `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
`addBos` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
Whether to add a bos to the text. #### Returns [IEnumerable<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)
### **DeTokenize(IEnumerable<Int32>)** Detokenize the tokens to text. ```csharp public string DeTokenize(IEnumerable tokens) ``` #### Parameters `tokens` [IEnumerable<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)
#### Returns [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
### **SaveState(String)** Save the state to specified path. ```csharp public void SaveState(string filename) ``` #### Parameters `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
### **GetStateData()** Get the state data as a byte array. ```csharp public Byte[] GetStateData() ``` #### Returns [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)
### **LoadState(String)** Load the state from specified path. ```csharp public void LoadState(string filename) ``` #### Parameters `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)
#### Exceptions [RuntimeError](./llama.exceptions.runtimeerror.md)
### **LoadState(Byte[])** Load the state from memory. ```csharp public void LoadState(Byte[] stateData) ``` #### Parameters `stateData` [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)
#### Exceptions [RuntimeError](./llama.exceptions.runtimeerror.md)
### **Sample(LLamaTokenDataArray, Single, MiroStateType, Single, Single, Int32, Single, Single, Single)** Perform the sampling. Please don't use it unless you fully know what it does. ```csharp public int Sample(LLamaTokenDataArray candidates, float temperature, MiroStateType mirostat, float mirostatTau, float mirostatEta, int topK, float topP, float tfsZ, float typicalP) ``` #### Parameters `candidates` [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)
`temperature` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`mirostat` [MiroStateType](./llama.common.mirostatetype.md)
`mirostatTau` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`mirostatEta` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`topK` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
`topP` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`tfsZ` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`typicalP` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
#### Returns [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
### **ApplyPenalty(IEnumerable<Int32>, Dictionary<Int32, Single>, Int32, Single, Single, Single, Boolean)** Apply the penalty for the tokens. Please don't use it unless you fully know what it does. ```csharp public LLamaTokenDataArray ApplyPenalty(IEnumerable lastTokens, Dictionary logitBias, int repeatLastTokensCount, float repeatPenalty, float alphaFrequency, float alphaPresence, bool penalizeNL) ``` #### Parameters `lastTokens` [IEnumerable<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)
`logitBias` [Dictionary<Int32, Single>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)
`repeatLastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
`repeatPenalty` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`alphaFrequency` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`alphaPresence` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)
`penalizeNL` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
#### Returns [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)
### **Eval(Int32[], Int32)** ```csharp public int Eval(Int32[] tokens, int pastTokensCount) ``` #### Parameters `tokens` [Int32[]](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
`pastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
#### Returns [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)
The updated `pastTokensCount`. #### Exceptions [RuntimeError](./llama.exceptions.runtimeerror.md)
### **GenerateResult(IEnumerable<Int32>)** ```csharp internal IEnumerable GenerateResult(IEnumerable ids) ``` #### Parameters `ids` [IEnumerable<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)
#### Returns [IEnumerable<String>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)
### **Dispose()** ```csharp public void Dispose() ```