Browse Source

feat: enable history for chat session.

tags/v0.2.2
Yaohui Liu 3 years ago
parent
commit
f5a01c346d
No known key found for this signature in database GPG Key ID: E86D01E1809BD23E
1 changed files with 8 additions and 1 deletions
  1. +8
    -1
      LLama/ChatSession.cs

+ 8
- 1
LLama/ChatSession.cs View File

@@ -18,7 +18,14 @@ namespace LLama

public IEnumerable<string> Chat(string text, string? prompt = null)
{
return _model.Chat(text, prompt);
History.Add(new ChatMessageRecord(new ChatCompletionMessage(ChatRole.Human, text), DateTime.Now));
string totalResponse = "";
foreach(var response in _model.Chat(text, prompt))
{
totalResponse += response;
yield return response;
}
History.Add(new ChatMessageRecord(new ChatCompletionMessage(ChatRole.Assistant, totalResponse), DateTime.Now));
}

public ChatSession<T> WithPrompt(string prompt)


Loading…
Cancel
Save