You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

llama.utils.md 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Utils
  2. Namespace: LLama
  3. Assorted llama utilities
  4. ```csharp
  5. public static class Utils
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Utils](./llama.utils.md)
  8. ## Methods
  9. ### **InitLLamaContextFromModelParams(IModelParams)**
  10. #### Caution
  11. Use LLamaWeights.LoadFromFile and LLamaWeights.CreateContext instead
  12. ---
  13. ```csharp
  14. public static SafeLLamaContextHandle InitLLamaContextFromModelParams(IModelParams params)
  15. ```
  16. #### Parameters
  17. `params` [IModelParams](./llama.abstractions.imodelparams.md)<br>
  18. #### Returns
  19. [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  20. ### **Tokenize(SafeLLamaContextHandle, String, Boolean, Encoding)**
  21. #### Caution
  22. Use SafeLLamaContextHandle Tokenize method instead
  23. ---
  24. ```csharp
  25. public static IEnumerable<int> Tokenize(SafeLLamaContextHandle ctx, string text, bool add_bos, Encoding encoding)
  26. ```
  27. #### Parameters
  28. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  29. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  30. `add_bos` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  31. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  32. #### Returns
  33. [IEnumerable&lt;Int32&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  34. ### **GetLogits(SafeLLamaContextHandle, Int32)**
  35. #### Caution
  36. Use SafeLLamaContextHandle GetLogits method instead
  37. ---
  38. ```csharp
  39. public static Span<float> GetLogits(SafeLLamaContextHandle ctx, int length)
  40. ```
  41. #### Parameters
  42. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  43. `length` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  44. #### Returns
  45. [Span&lt;Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>
  46. ### **Eval(SafeLLamaContextHandle, Int32[], Int32, Int32, Int32, Int32)**
  47. #### Caution
  48. Use SafeLLamaContextHandle Eval method instead
  49. ---
  50. ```csharp
  51. public static int Eval(SafeLLamaContextHandle ctx, Int32[] tokens, int startIndex, int n_tokens, int n_past, int n_threads)
  52. ```
  53. #### Parameters
  54. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  55. `tokens` [Int32[]](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  56. `startIndex` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  57. `n_tokens` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  58. `n_past` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  59. `n_threads` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  60. #### Returns
  61. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  62. ### **TokenToString(Int32, SafeLLamaContextHandle, Encoding)**
  63. #### Caution
  64. Use SafeLLamaContextHandle TokenToString method instead
  65. ---
  66. ```csharp
  67. public static string TokenToString(int token, SafeLLamaContextHandle ctx, Encoding encoding)
  68. ```
  69. #### Parameters
  70. `token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  71. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  72. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  73. #### Returns
  74. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  75. ### **PtrToString(IntPtr, Encoding)**
  76. #### Caution
  77. No longer used internally by LlamaSharp
  78. ---
  79. ```csharp
  80. public static string PtrToString(IntPtr ptr, Encoding encoding)
  81. ```
  82. #### Parameters
  83. `ptr` [IntPtr](https://docs.microsoft.com/en-us/dotnet/api/system.intptr)<br>
  84. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  85. #### Returns
  86. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>