using System; using System.Collections.Generic; using System.IO; #pragma warning disable // ReSharper disable all namespace LLama.OldVersion { [Obsolete("The entire LLama.OldVersion namespace will be removed")] public class ChatSession where T : IChatModel { IChatModel _model; List History { get; } = new List(); public ChatSession(T model) { _model = model; } public IEnumerable Chat(string text, string? prompt = null, string encoding = "UTF-8") { History.Add(new ChatMessageRecord(new ChatCompletionMessage(ChatRole.Human, text), DateTime.Now)); string totalResponse = ""; foreach (var response in _model.Chat(text, prompt, encoding)) { totalResponse += response; yield return response; } History.Add(new ChatMessageRecord(new ChatCompletionMessage(ChatRole.Assistant, totalResponse), DateTime.Now)); } public ChatSession WithPrompt(string prompt, string encoding = "UTF-8") { _model.InitChatPrompt(prompt, encoding); return this; } public ChatSession WithPromptFile(string promptFilename, string encoding = "UTF-8") { return WithPrompt(File.ReadAllText(promptFilename), encoding); } /// /// Set the keywords to split the return value of chat AI. /// /// /// public ChatSession WithAntiprompt(string[] antiprompt) { _model.InitChatAntiprompt(antiprompt); return this; } } }