From f5a01c346ddb579dfa67e18c6f7492bedb855062 Mon Sep 17 00:00:00 2001 From: Yaohui Liu Date: Tue, 16 May 2023 02:54:22 +0800 Subject: [PATCH] feat: enable history for chat session. --- LLama/ChatSession.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/LLama/ChatSession.cs b/LLama/ChatSession.cs index a3a50665..c6cd0a84 100644 --- a/LLama/ChatSession.cs +++ b/LLama/ChatSession.cs @@ -18,7 +18,14 @@ namespace LLama public IEnumerable 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 WithPrompt(string prompt)