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.streamingtokendecoder.md 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. # StreamingTokenDecoder
  2. Namespace: LLama
  3. Decodes a stream of tokens into a stream of characters
  4. ```csharp
  5. public sealed class StreamingTokenDecoder
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [StreamingTokenDecoder](./llama.streamingtokendecoder.md)
  8. ## Properties
  9. ### **AvailableCharacters**
  10. The number of decoded characters waiting to be read
  11. ```csharp
  12. public int AvailableCharacters { get; }
  13. ```
  14. #### Property Value
  15. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  16. ## Constructors
  17. ### **StreamingTokenDecoder(Encoding, LLamaWeights)**
  18. Create a new decoder
  19. ```csharp
  20. public StreamingTokenDecoder(Encoding encoding, LLamaWeights weights)
  21. ```
  22. #### Parameters
  23. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  24. Text encoding to use
  25. `weights` [LLamaWeights](./llama.llamaweights.md)<br>
  26. Model weights
  27. ### **StreamingTokenDecoder(LLamaContext)**
  28. Create a new decoder
  29. ```csharp
  30. public StreamingTokenDecoder(LLamaContext context)
  31. ```
  32. #### Parameters
  33. `context` [LLamaContext](./llama.llamacontext.md)<br>
  34. Context to retrieve encoding and model weights from
  35. ### **StreamingTokenDecoder(Encoding, SafeLLamaContextHandle)**
  36. Create a new decoder
  37. ```csharp
  38. public StreamingTokenDecoder(Encoding encoding, SafeLLamaContextHandle context)
  39. ```
  40. #### Parameters
  41. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  42. Text encoding to use
  43. `context` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  44. Context to retrieve model weights from
  45. ### **StreamingTokenDecoder(Encoding, SafeLlamaModelHandle)**
  46. Create a new decoder
  47. ```csharp
  48. public StreamingTokenDecoder(Encoding encoding, SafeLlamaModelHandle weights)
  49. ```
  50. #### Parameters
  51. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  52. Text encoding to use
  53. `weights` [SafeLlamaModelHandle](./llama.native.safellamamodelhandle.md)<br>
  54. Models weights to use
  55. ## Methods
  56. ### **Add(LLamaToken)**
  57. Add a single token to the decoder
  58. ```csharp
  59. public void Add(LLamaToken token)
  60. ```
  61. #### Parameters
  62. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  63. ### **Add(Int32)**
  64. Add a single token to the decoder
  65. ```csharp
  66. public void Add(int token)
  67. ```
  68. #### Parameters
  69. `token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  70. ### **AddRange&lt;T&gt;(T)**
  71. Add all tokens in the given enumerable
  72. ```csharp
  73. public void AddRange<T>(T tokens)
  74. ```
  75. #### Type Parameters
  76. `T`<br>
  77. #### Parameters
  78. `tokens` T<br>
  79. ### **AddRange(ReadOnlySpan&lt;LLamaToken&gt;)**
  80. Add all tokens in the given span
  81. ```csharp
  82. public void AddRange(ReadOnlySpan<LLamaToken> tokens)
  83. ```
  84. #### Parameters
  85. `tokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  86. ### **Read(List&lt;Char&gt;)**
  87. Read all decoded characters and clear the buffer
  88. ```csharp
  89. public void Read(List<char> dest)
  90. ```
  91. #### Parameters
  92. `dest` [List&lt;Char&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
  93. ### **Read()**
  94. Read all decoded characters as a string and clear the buffer
  95. ```csharp
  96. public string Read()
  97. ```
  98. #### Returns
  99. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  100. ### **Reset()**
  101. Set the decoder back to its initial state
  102. ```csharp
  103. public void Reset()
  104. ```
  105. ### **&lt;Add&gt;g__TokenToBytes|9_0(Byte[]&, LLamaToken, SafeLlamaModelHandle)**
  106. ```csharp
  107. internal static Span<byte> <Add>g__TokenToBytes|9_0(Byte[]& bytes, LLamaToken token, SafeLlamaModelHandle model)
  108. ```
  109. #### Parameters
  110. `bytes` [Byte[]&](https://docs.microsoft.com/en-us/dotnet/api/system.byte&)<br>
  111. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  112. `model` [SafeLlamaModelHandle](./llama.native.safellamamodelhandle.md)<br>
  113. #### Returns
  114. [Span&lt;Byte&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>