From 601b64b50aebbf315df96b9f02b3d0244d039e30 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 1 Apr 2024 21:10:21 -0500 Subject: [PATCH] Prevent duplicate record to be inserted --- .../Conversations/Services/ConversationStorage.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs index 33717410..7711c37b 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs @@ -38,6 +38,13 @@ public class ConversationStorage : IConversationStorage 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