您最多选择25个标签 标签必须以中文、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

llama.oldversion.llamamodel.md 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. # LLamaModel
  2. Namespace: LLama.OldVersion
  3. ```csharp
  4. public class LLamaModel : IChatModel, System.IDisposable
  5. ```
  6. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [LLamaModel](./llama.oldversion.llamamodel.md)<br>
  7. Implements [IChatModel](./llama.oldversion.ichatmodel.md), [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)
  8. ## Properties
  9. ### **Name**
  10. ```csharp
  11. public string Name { get; set; }
  12. ```
  13. #### Property Value
  14. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  15. ### **Verbose**
  16. ```csharp
  17. public bool Verbose { get; set; }
  18. ```
  19. #### Property Value
  20. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  21. ### **NativeHandle**
  22. ```csharp
  23. public SafeLLamaContextHandle NativeHandle { get; }
  24. ```
  25. #### Property Value
  26. [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  27. ## Constructors
  28. ### **LLamaModel(String, String, Boolean, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Dictionary&lt;Int32, Single&gt;, Int32, Single, Single, Single, Single, Single, Int32, Single, Single, Int32, Single, Single, String, String, String, String, List&lt;String&gt;, String, String, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, String)**
  29. Please refer `LLamaParams` to find the meanings of each arg. Be sure to have set the `n_gpu_layers`, otherwise it will
  30. load 20 layers to gpu by default.
  31. ```csharp
  32. public LLamaModel(string model_path, string model_name, bool verbose, int seed, int n_threads, int n_predict, int n_ctx, int n_batch, int n_keep, int n_gpu_layers, Dictionary<int, float> logit_bias, int top_k, float top_p, float tfs_z, float typical_p, float temp, float repeat_penalty, int repeat_last_n, float frequency_penalty, float presence_penalty, int mirostat, float mirostat_tau, float mirostat_eta, string prompt, string path_session, string input_prefix, string input_suffix, List<string> antiprompt, string lora_adapter, string lora_base, bool memory_f16, bool random_prompt, bool use_color, bool interactive, bool embedding, bool interactive_first, bool prompt_cache_all, bool instruct, bool penalize_nl, bool perplexity, bool use_mmap, bool use_mlock, bool mem_test, bool verbose_prompt, string encoding)
  33. ```
  34. #### Parameters
  35. `model_path` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  36. The model file path.
  37. `model_name` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  38. The model name.
  39. `verbose` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  40. Whether to print details when running the model.
  41. `seed` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  42. `n_threads` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  43. `n_predict` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  44. `n_ctx` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  45. `n_batch` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  46. `n_keep` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  47. `n_gpu_layers` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  48. `logit_bias` [Dictionary&lt;Int32, Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)<br>
  49. `top_k` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  50. `top_p` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  51. `tfs_z` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  52. `typical_p` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  53. `temp` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  54. `repeat_penalty` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  55. `repeat_last_n` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  56. `frequency_penalty` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  57. `presence_penalty` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  58. `mirostat` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  59. `mirostat_tau` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  60. `mirostat_eta` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  61. `prompt` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  62. `path_session` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  63. `input_prefix` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  64. `input_suffix` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  65. `antiprompt` [List&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
  66. `lora_adapter` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  67. `lora_base` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  68. `memory_f16` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  69. `random_prompt` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  70. `use_color` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  71. `interactive` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  72. `embedding` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  73. `interactive_first` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  74. `prompt_cache_all` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  75. `instruct` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  76. `penalize_nl` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  77. `perplexity` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  78. `use_mmap` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  79. `use_mlock` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  80. `mem_test` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  81. `verbose_prompt` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  82. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  83. ### **LLamaModel(LLamaParams, String, Boolean, String)**
  84. Please refer `LLamaParams` to find the meanings of each arg. Be sure to have set the `n_gpu_layers`, otherwise it will
  85. load 20 layers to gpu by default.
  86. ```csharp
  87. public LLamaModel(LLamaParams params, string name, bool verbose, string encoding)
  88. ```
  89. #### Parameters
  90. `params` [LLamaParams](./llama.oldversion.llamaparams.md)<br>
  91. The LLamaModel params
  92. `name` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  93. Model name
  94. `verbose` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  95. Whether to output the detailed info.
  96. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  97. #### Exceptions
  98. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  99. ## Methods
  100. ### **WithPrompt(String, String)**
  101. Apply a prompt to the model.
  102. ```csharp
  103. public LLamaModel WithPrompt(string prompt, string encoding)
  104. ```
  105. #### Parameters
  106. `prompt` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  107. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  108. #### Returns
  109. [LLamaModel](./llama.oldversion.llamamodel.md)<br>
  110. #### Exceptions
  111. [ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
  112. ### **WithPromptFile(String)**
  113. Apply the prompt file to the model.
  114. ```csharp
  115. public LLamaModel WithPromptFile(string promptFileName)
  116. ```
  117. #### Parameters
  118. `promptFileName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  119. #### Returns
  120. [LLamaModel](./llama.oldversion.llamamodel.md)<br>
  121. ### **InitChatPrompt(String, String)**
  122. ```csharp
  123. public void InitChatPrompt(string prompt, string encoding)
  124. ```
  125. #### Parameters
  126. `prompt` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  127. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  128. ### **InitChatAntiprompt(String[])**
  129. ```csharp
  130. public void InitChatAntiprompt(String[] antiprompt)
  131. ```
  132. #### Parameters
  133. `antiprompt` [String[]](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  134. ### **Chat(String, String, String)**
  135. Chat with the LLaMa model under interactive mode.
  136. ```csharp
  137. public IEnumerable<string> Chat(string text, string prompt, string encoding)
  138. ```
  139. #### Parameters
  140. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  141. `prompt` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  142. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  143. #### Returns
  144. [IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  145. #### Exceptions
  146. [ArgumentException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentexception)<br>
  147. ### **SaveState(String)**
  148. Save the state to specified path.
  149. ```csharp
  150. public void SaveState(string filename)
  151. ```
  152. #### Parameters
  153. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  154. ### **LoadState(String, Boolean)**
  155. Load the state from specified path.
  156. ```csharp
  157. public void LoadState(string filename, bool clearPreviousEmbed)
  158. ```
  159. #### Parameters
  160. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  161. `clearPreviousEmbed` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  162. Whether to clear previous footprints of this model.
  163. #### Exceptions
  164. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  165. ### **Tokenize(String, String)**
  166. Tokenize a string.
  167. ```csharp
  168. public List<int> Tokenize(string text, string encoding)
  169. ```
  170. #### Parameters
  171. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  172. The utf-8 encoded string to tokenize.
  173. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  174. #### Returns
  175. [List&lt;Int32&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
  176. A list of tokens.
  177. #### Exceptions
  178. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  179. If the tokenization failed.
  180. ### **DeTokenize(IEnumerable&lt;Int32&gt;)**
  181. Detokenize a list of tokens.
  182. ```csharp
  183. public string DeTokenize(IEnumerable<int> tokens)
  184. ```
  185. #### Parameters
  186. `tokens` [IEnumerable&lt;Int32&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  187. The list of tokens to detokenize.
  188. #### Returns
  189. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  190. The detokenized string.
  191. ### **Call(String, String)**
  192. Call the model to run inference.
  193. ```csharp
  194. public IEnumerable<string> Call(string text, string encoding)
  195. ```
  196. #### Parameters
  197. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  198. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  199. #### Returns
  200. [IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  201. #### Exceptions
  202. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  203. ### **Dispose()**
  204. ```csharp
  205. public void Dispose()
  206. ```