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.chatsession.md 5.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. # ChatSession
  2. Namespace: LLama
  3. The main chat session class.
  4. ```csharp
  5. public class ChatSession
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ChatSession](./llama.chatsession.md)
  8. ## Fields
  9. ### **OutputTransform**
  10. The output transform used in this session.
  11. ```csharp
  12. public ITextStreamTransform OutputTransform;
  13. ```
  14. ## Properties
  15. ### **Executor**
  16. The executor for this session.
  17. ```csharp
  18. public ILLamaExecutor Executor { get; }
  19. ```
  20. #### Property Value
  21. [ILLamaExecutor](./llama.abstractions.illamaexecutor.md)<br>
  22. ### **History**
  23. The chat history for this session.
  24. ```csharp
  25. public ChatHistory History { get; }
  26. ```
  27. #### Property Value
  28. [ChatHistory](./llama.common.chathistory.md)<br>
  29. ### **HistoryTransform**
  30. The history transform used in this session.
  31. ```csharp
  32. public IHistoryTransform HistoryTransform { get; set; }
  33. ```
  34. #### Property Value
  35. [IHistoryTransform](./llama.abstractions.ihistorytransform.md)<br>
  36. ### **InputTransformPipeline**
  37. The input transform pipeline used in this session.
  38. ```csharp
  39. public List<ITextTransform> InputTransformPipeline { get; set; }
  40. ```
  41. #### Property Value
  42. [List&lt;ITextTransform&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
  43. ## Constructors
  44. ### **ChatSession(ILLamaExecutor)**
  45. ```csharp
  46. public ChatSession(ILLamaExecutor executor)
  47. ```
  48. #### Parameters
  49. `executor` [ILLamaExecutor](./llama.abstractions.illamaexecutor.md)<br>
  50. The executor for this session
  51. ## Methods
  52. ### **WithHistoryTransform(IHistoryTransform)**
  53. Use a custom history transform.
  54. ```csharp
  55. public ChatSession WithHistoryTransform(IHistoryTransform transform)
  56. ```
  57. #### Parameters
  58. `transform` [IHistoryTransform](./llama.abstractions.ihistorytransform.md)<br>
  59. #### Returns
  60. [ChatSession](./llama.chatsession.md)<br>
  61. ### **AddInputTransform(ITextTransform)**
  62. Add a text transform to the input transform pipeline.
  63. ```csharp
  64. public ChatSession AddInputTransform(ITextTransform transform)
  65. ```
  66. #### Parameters
  67. `transform` [ITextTransform](./llama.abstractions.itexttransform.md)<br>
  68. #### Returns
  69. [ChatSession](./llama.chatsession.md)<br>
  70. ### **WithOutputTransform(ITextStreamTransform)**
  71. Use a custom output transform.
  72. ```csharp
  73. public ChatSession WithOutputTransform(ITextStreamTransform transform)
  74. ```
  75. #### Parameters
  76. `transform` [ITextStreamTransform](./llama.abstractions.itextstreamtransform.md)<br>
  77. #### Returns
  78. [ChatSession](./llama.chatsession.md)<br>
  79. ### **SaveSession(String)**
  80. ```csharp
  81. public void SaveSession(string path)
  82. ```
  83. #### Parameters
  84. `path` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  85. The directory name to save the session. If the directory does not exist, a new directory will be created.
  86. ### **LoadSession(String)**
  87. ```csharp
  88. public void LoadSession(string path)
  89. ```
  90. #### Parameters
  91. `path` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  92. The directory name to load the session.
  93. ### **Chat(ChatHistory, InferenceParams, CancellationToken)**
  94. Get the response from the LLama model with chat histories.
  95. ```csharp
  96. public IEnumerable<string> Chat(ChatHistory history, InferenceParams inferenceParams, CancellationToken cancellationToken)
  97. ```
  98. #### Parameters
  99. `history` [ChatHistory](./llama.common.chathistory.md)<br>
  100. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  101. `cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)<br>
  102. #### Returns
  103. [IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  104. ### **Chat(String, InferenceParams, CancellationToken)**
  105. Get the response from the LLama model. Note that prompt could not only be the preset words,
  106. but also the question you want to ask.
  107. ```csharp
  108. public IEnumerable<string> Chat(string prompt, InferenceParams inferenceParams, CancellationToken cancellationToken)
  109. ```
  110. #### Parameters
  111. `prompt` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  112. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  113. `cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)<br>
  114. #### Returns
  115. [IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  116. ### **ChatAsync(ChatHistory, InferenceParams, CancellationToken)**
  117. Get the response from the LLama model with chat histories.
  118. ```csharp
  119. public IAsyncEnumerable<string> ChatAsync(ChatHistory history, InferenceParams inferenceParams, CancellationToken cancellationToken)
  120. ```
  121. #### Parameters
  122. `history` [ChatHistory](./llama.common.chathistory.md)<br>
  123. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  124. `cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)<br>
  125. #### Returns
  126. [IAsyncEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1)<br>
  127. ### **ChatAsync(String, InferenceParams, CancellationToken)**
  128. Get the response from the LLama model with chat histories asynchronously.
  129. ```csharp
  130. public IAsyncEnumerable<string> ChatAsync(string prompt, InferenceParams inferenceParams, CancellationToken cancellationToken)
  131. ```
  132. #### Parameters
  133. `prompt` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  134. `inferenceParams` [InferenceParams](./llama.common.inferenceparams.md)<br>
  135. `cancellationToken` [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken)<br>
  136. #### Returns
  137. [IAsyncEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1)<br>