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.batched.conversation.md 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. # Conversation
  2. Namespace: LLama.Batched
  3. A single conversation thread that can be prompted (adding tokens from the user) or inferred (extracting a token from the LLM)
  4. ```csharp
  5. public sealed class Conversation : System.IDisposable
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Conversation](./llama.batched.conversation.md)<br>
  8. Implements [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)
  9. ## Properties
  10. ### **Executor**
  11. The executor which this conversation belongs to
  12. ```csharp
  13. public BatchedExecutor Executor { get; }
  14. ```
  15. #### Property Value
  16. [BatchedExecutor](./llama.batched.batchedexecutor.md)<br>
  17. ### **ConversationId**
  18. Unique ID for this conversation
  19. ```csharp
  20. public LLamaSeqId ConversationId { get; }
  21. ```
  22. #### Property Value
  23. [LLamaSeqId](./llama.native.llamaseqid.md)<br>
  24. ### **TokenCount**
  25. Total number of tokens in this conversation, cannot exceed the context length.
  26. ```csharp
  27. public int TokenCount { get; }
  28. ```
  29. #### Property Value
  30. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  31. ### **IsDisposed**
  32. Indicates if this conversation has been disposed, nothing can be done with a disposed conversation
  33. ```csharp
  34. public bool IsDisposed { get; }
  35. ```
  36. #### Property Value
  37. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  38. ### **RequiresInference**
  39. Indicates if this conversation is waiting for inference to be run on the executor. "Prompt" and "Sample" cannot be called when this is true.
  40. ```csharp
  41. public bool RequiresInference { get; }
  42. ```
  43. #### Property Value
  44. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  45. ### **RequiresSampling**
  46. Indicates that this conversation should be sampled.
  47. ```csharp
  48. public bool RequiresSampling { get; }
  49. ```
  50. #### Property Value
  51. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  52. ## Methods
  53. ### **Finalize()**
  54. Finalizer for Conversation
  55. ```csharp
  56. protected void Finalize()
  57. ```
  58. ### **Dispose()**
  59. End this conversation, freeing all resources used by it
  60. ```csharp
  61. public void Dispose()
  62. ```
  63. #### Exceptions
  64. [ObjectDisposedException](https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception)<br>
  65. ### **Fork()**
  66. Create a copy of the current conversation
  67. ```csharp
  68. public Conversation Fork()
  69. ```
  70. #### Returns
  71. [Conversation](./llama.batched.conversation.md)<br>
  72. #### Exceptions
  73. [ObjectDisposedException](https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception)<br>
  74. **Remarks:**
  75. The copy shares internal state, so consumes very little extra memory.
  76. ### **Sample()**
  77. Get the logits from this conversation, ready for sampling
  78. ```csharp
  79. public Span<float> Sample()
  80. ```
  81. #### Returns
  82. [Span&lt;Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>
  83. #### Exceptions
  84. [ObjectDisposedException](https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception)<br>
  85. [CannotSampleRequiresPromptException](./llama.batched.cannotsamplerequirespromptexception.md)<br>
  86. Thrown if this conversation was not prompted before the previous call to infer
  87. [CannotSampleRequiresInferenceException](./llama.batched.cannotsamplerequiresinferenceexception.md)<br>
  88. Thrown if Infer() must be called on the executor
  89. ### **Prompt(String)**
  90. Add tokens to this conversation
  91. ```csharp
  92. public void Prompt(string input)
  93. ```
  94. #### Parameters
  95. `input` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  96. ### **Prompt(List&lt;LLamaToken&gt;)**
  97. Add tokens to this conversation
  98. ```csharp
  99. public void Prompt(List<LLamaToken> tokens)
  100. ```
  101. #### Parameters
  102. `tokens` [List&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
  103. #### Exceptions
  104. [ObjectDisposedException](https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception)<br>
  105. [AlreadyPromptedConversationException](./llama.batched.alreadypromptedconversationexception.md)<br>
  106. ### **Prompt(ReadOnlySpan&lt;LLamaToken&gt;)**
  107. Add tokens to this conversation
  108. ```csharp
  109. public void Prompt(ReadOnlySpan<LLamaToken> tokens)
  110. ```
  111. #### Parameters
  112. `tokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  113. #### Exceptions
  114. [ObjectDisposedException](https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception)<br>
  115. [AlreadyPromptedConversationException](./llama.batched.alreadypromptedconversationexception.md)<br>
  116. ### **Prompt(LLamaToken)**
  117. Add a single token to this conversation
  118. ```csharp
  119. public void Prompt(LLamaToken token)
  120. ```
  121. #### Parameters
  122. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  123. #### Exceptions
  124. [ObjectDisposedException](https://docs.microsoft.com/en-us/dotnet/api/system.objectdisposedexception)<br>
  125. [AlreadyPromptedConversationException](./llama.batched.alreadypromptedconversationexception.md)<br>
  126. ### **Modify(ModifyKvCache)**
  127. Directly modify the KV cache of this conversation
  128. ```csharp
  129. public void Modify(ModifyKvCache modifier)
  130. ```
  131. #### Parameters
  132. `modifier` [ModifyKvCache](./llama.batched.conversation.modifykvcache.md)<br>
  133. #### Exceptions
  134. [CannotModifyWhileRequiresInferenceException](./llama.batched.cannotmodifywhilerequiresinferenceexception.md)<br>
  135. Thrown if this method is called while [Conversation.RequiresInference](./llama.batched.conversation.md#requiresinference) == true