|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- # LLamaContext
-
- Namespace: LLama
-
- A llama_context, which holds all the context required to interact with a model
-
- ```csharp
- public sealed class LLamaContext : System.IDisposable
- ```
-
- Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [LLamaContext](./llama.llamacontext.md)<br>
- Implements [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)
-
- ## Properties
-
- ### **VocabCount**
-
- Total number of tokens in vocabulary of this model
-
- ```csharp
- public int VocabCount { get; }
- ```
-
- #### Property Value
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- ### **ContextSize**
-
- Total number of tokens in the context
-
- ```csharp
- public int ContextSize { get; }
- ```
-
- #### Property Value
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- ### **EmbeddingSize**
-
- Dimension of embedding vectors
-
- ```csharp
- public int EmbeddingSize { get; }
- ```
-
- #### Property Value
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- ### **Params**
-
- The model params set for this model.
-
- ```csharp
- public IModelParams Params { get; set; }
- ```
-
- #### Property Value
-
- [IModelParams](./llama.abstractions.imodelparams.md)<br>
-
- ### **NativeHandle**
-
- The native handle, which is used to be passed to the native APIs
-
- ```csharp
- public SafeLLamaContextHandle NativeHandle { get; }
- ```
-
- #### Property Value
-
- [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
-
- **Remarks:**
-
- Be careful how you use this!
-
- ### **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)<br>
-
- ### **EmbeddingLength**
-
- The embedding length of the model, also known as `n_embed`
-
- ```csharp
- public int EmbeddingLength { get; }
- ```
-
- #### Property Value
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- ## Constructors
-
- ### **LLamaContext(IModelParams, ILLamaLogger)**
-
- #### Caution
-
- Use the LLamaWeights.CreateContext instead
-
- ---
-
-
-
- ```csharp
- public LLamaContext(IModelParams params, ILLamaLogger logger)
- ```
-
- #### Parameters
-
- `params` [IModelParams](./llama.abstractions.imodelparams.md)<br>
- Model params.
-
- `logger` [ILLamaLogger](./llama.common.illamalogger.md)<br>
- The logger.
-
- ### **LLamaContext(LLamaWeights, IModelParams, ILLamaLogger)**
-
- Create a new LLamaContext for the given LLamaWeights
-
- ```csharp
- public LLamaContext(LLamaWeights model, IModelParams params, ILLamaLogger logger)
- ```
-
- #### Parameters
-
- `model` [LLamaWeights](./llama.llamaweights.md)<br>
-
- `params` [IModelParams](./llama.abstractions.imodelparams.md)<br>
-
- `logger` [ILLamaLogger](./llama.common.illamalogger.md)<br>
-
- #### Exceptions
-
- [ObjectDisposedException](https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception)<br>
-
- ## Methods
-
- ### **Clone()**
-
- Create a copy of the current state of this context
-
- ```csharp
- public LLamaContext Clone()
- ```
-
- #### Returns
-
- [LLamaContext](./llama.llamacontext.md)<br>
-
- ### **Tokenize(String, Boolean)**
-
- Tokenize a string.
-
- ```csharp
- public Int32[] Tokenize(string text, bool addBos)
- ```
-
- #### Parameters
-
- `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
-
- `addBos` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
- Whether to add a bos to the text.
-
- #### Returns
-
- [Int32[]](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- ### **DeTokenize(IEnumerable<Int32>)**
-
- Detokenize the tokens to text.
-
- ```csharp
- public string DeTokenize(IEnumerable<int> tokens)
- ```
-
- #### Parameters
-
- `tokens` [IEnumerable<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
-
- #### Returns
-
- [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
-
- ### **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)<br>
-
- ### **GetStateData()**
-
- #### Caution
-
- Use `GetState` instead, this supports larger states (over 2GB)
-
- ---
-
- Get the state data as a byte array.
-
- ```csharp
- public Byte[] GetStateData()
- ```
-
- #### Returns
-
- [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
-
- ### **GetState()**
-
- Get the state data as an opaque handle
-
- ```csharp
- public State GetState()
- ```
-
- #### Returns
-
- [State](./llama.llamacontext.state.md)<br>
-
- ### **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)<br>
-
- #### Exceptions
-
- [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
-
- ### **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)<br>
-
- #### Exceptions
-
- [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
-
- ### **LoadState(State)**
-
- Load the state from memory.
-
- ```csharp
- public void LoadState(State state)
- ```
-
- #### Parameters
-
- `state` [State](./llama.llamacontext.state.md)<br>
-
- #### Exceptions
-
- [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
-
- ### **Sample(LLamaTokenDataArray, Nullable`1&, Single, MirostatType, Single, Single, Int32, Single, Single, Single, SafeLLamaGrammarHandle)**
-
- Perform the sampling. Please don't use it unless you fully know what it does.
-
- ```csharp
- public int Sample(LLamaTokenDataArray candidates, Nullable`1& mirostat_mu, float temperature, MirostatType mirostat, float mirostatTau, float mirostatEta, int topK, float topP, float tfsZ, float typicalP, SafeLLamaGrammarHandle grammar)
- ```
-
- #### Parameters
-
- `candidates` [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)<br>
-
- `mirostat_mu` [Nullable`1&](https://docs.microsoft.com/en-us/dotnet/api/system.nullable-1&)<br>
-
- `temperature` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `mirostat` [MirostatType](./llama.common.mirostattype.md)<br>
-
- `mirostatTau` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `mirostatEta` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `topK` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- `topP` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `tfsZ` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `typicalP` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `grammar` [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)<br>
-
- #### Returns
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- ### **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<int> lastTokens, Dictionary<int, float> 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)<br>
-
- `logitBias` [Dictionary<Int32, Single>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)<br>
-
- `repeatLastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- `repeatPenalty` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `alphaFrequency` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `alphaPresence` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
-
- `penalizeNL` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
-
- #### Returns
-
- [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)<br>
-
- ### **Eval(Int32[], Int32)**
-
-
-
- ```csharp
- public int Eval(Int32[] tokens, int pastTokensCount)
- ```
-
- #### Parameters
-
- `tokens` [Int32[]](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- `pastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- #### Returns
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
- The updated `pastTokensCount`.
-
- #### Exceptions
-
- [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
-
- ### **Eval(List<Int32>, Int32)**
-
-
-
- ```csharp
- public int Eval(List<int> tokens, int pastTokensCount)
- ```
-
- #### Parameters
-
- `tokens` [List<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
-
- `pastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- #### Returns
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
- The updated `pastTokensCount`.
-
- #### Exceptions
-
- [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
-
- ### **Eval(ReadOnlyMemory<Int32>, Int32)**
-
-
-
- ```csharp
- public int Eval(ReadOnlyMemory<int> tokens, int pastTokensCount)
- ```
-
- #### Parameters
-
- `tokens` [ReadOnlyMemory<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.readonlymemory-1)<br>
-
- `pastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- #### Returns
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
- The updated `pastTokensCount`.
-
- #### Exceptions
-
- [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
-
- ### **Eval(ReadOnlySpan<Int32>, Int32)**
-
-
-
- ```csharp
- public int Eval(ReadOnlySpan<int> tokens, int pastTokensCount)
- ```
-
- #### Parameters
-
- `tokens` [ReadOnlySpan<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
-
- `pastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- #### Returns
-
- [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
- The updated `pastTokensCount`.
-
- #### Exceptions
-
- [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
-
- ### **GenerateResult(IEnumerable<Int32>)**
-
- ```csharp
- internal IEnumerable<string> GenerateResult(IEnumerable<int> ids)
- ```
-
- #### Parameters
-
- `ids` [IEnumerable<Int32>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
-
- #### Returns
-
- [IEnumerable<String>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
-
- ### **TokenToString(Int32)**
-
- Convert a token into a string
-
- ```csharp
- public string TokenToString(int token)
- ```
-
- #### Parameters
-
- `token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
-
- #### Returns
-
- [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
-
- ### **Dispose()**
-
- ```csharp
- public void Dispose()
- ```
|