From 71ea333eaebb957b827194bcf120051eadf329de Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 14 Apr 2025 14:45:33 -0500 Subject: [PATCH] merge code --- .../Services/ConversationStorage.cs | 70 +------------------ 1 file changed, 1 insertion(+), 69 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index 75d1a501..49852eb2 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -19,75 +19,7 @@ public class ConversationStorage : IConversationStorage public void Append(string conversationId, RoleDialogModel dialog) { - var agentId = dialog.CurrentAgentId; - var db = _services.GetRequiredService(); - var dialogElements = new List(); - - // Prevent duplicate record to be inserted - /*var dialogs = db.GetConversationDialogs(conversationId); - if (dialogs.Any(x => x.MetaData.MessageId == dialog.MessageId && x.Content == dialog.Content)) - { - return; - }*/ - - if (dialog.Role == AgentRole.Function) - { - var meta = new DialogMetaData - { - Role = dialog.Role, - AgentId = agentId, - MessageId = dialog.MessageId, - MessageType = dialog.MessageType, - FunctionName = dialog.FunctionName, - CreatedTime = dialog.CreatedAt - }; - - var content = dialog.Content.RemoveNewLine(); - if (string.IsNullOrEmpty(content)) - { - return; - } - dialogElements.Add(new DialogElement - { - MetaData = meta, - Content = dialog.Content, - SecondaryContent = dialog.SecondaryContent, - Payload = dialog.Payload - }); - } - else - { - var meta = new DialogMetaData - { - Role = dialog.Role, - AgentId = agentId, - MessageId = dialog.MessageId, - MessageType = dialog.MessageType, - SenderId = dialog.SenderId, - FunctionName = dialog.FunctionName, - CreatedTime = dialog.CreatedAt - }; - - var content = dialog.Content.RemoveNewLine(); - if (string.IsNullOrEmpty(content)) - { - return; - } - - var richContent = dialog.RichContent != null ? JsonSerializer.Serialize(dialog.RichContent, _options.JsonSerializerOptions) : null; - var secondaryRichContent = dialog.SecondaryRichContent != null ? JsonSerializer.Serialize(dialog.SecondaryRichContent, _options.JsonSerializerOptions) : null; - dialogElements.Add(new DialogElement - { - MetaData = meta, - Content = dialog.Content, - SecondaryContent = dialog.SecondaryContent, - RichContent = richContent, - SecondaryRichContent = secondaryRichContent, - Payload = dialog.Payload - }); - } - - db.AppendConversationDialogs(conversationId, dialogElements); + Append(conversationId, [dialog]); } public void Append(string conversationId, IEnumerable dialogs)