From e850381b9fea01e356f51bfc3f7388f4c5df5d7b Mon Sep 17 00:00:00 2001 From: Wenbo Cao <104199@smsassist.com> Date: Fri, 1 Sep 2023 13:37:18 -0500 Subject: [PATCH] Add filter when saving dialogue --- .../RoutingConversationHook.cs | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs b/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs index 15f0912f..869afe94 100644 --- a/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs +++ b/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs @@ -13,6 +13,7 @@ using BotSharp.Plugin.RoutingSpeeder.Providers; using System.Runtime.InteropServices; using BotSharp.Abstraction.Agents; using System.IO; +using BotSharp.Abstraction.Routing.Settings; namespace BotSharp.Plugin.RoutingSpeeder; @@ -49,20 +50,26 @@ public class RoutingConversationHook: ConversationHookBase public override async Task AfterCompletion(RoleDialogModel message) { - // save train data - var agentService = _services.CreateScope().ServiceProvider.GetRequiredService(); - var rootDataPath = agentService.GetDataDir(); + var routerSettings = _services.GetRequiredService(); + bool saveFlag = (message.CurrentAgentId != routerSettings.RouterId) && (message.CurrentAgentId != routerSettings.ReasonerId); - string rawDataDir = Path.Combine(rootDataPath, "raw_data", $"{message.CurrentAgentId}.txt"); - var lastThreeDialogs = _dialogs.Where(x => x.Role == AgentRole.User).Select(x => x.Content).Reverse().Take(3).ToArray(); + if (saveFlag) + { + // save train data + var agentService = _services.CreateScope().ServiceProvider.GetRequiredService(); + var rootDataPath = agentService.GetDataDir(); - if (!File.Exists(rawDataDir)) - { - await File.WriteAllLinesAsync(rawDataDir, lastThreeDialogs); - } - else - { - await File.AppendAllLinesAsync(rawDataDir, lastThreeDialogs); + string rawDataDir = Path.Combine(rootDataPath, "raw_data", $"{message.CurrentAgentId}.txt"); + var lastThreeDialogs = _dialogs.Where(x => x.Role == AgentRole.User).Select(x => x.Content).Reverse().Take(3).ToArray(); + + if (!File.Exists(rawDataDir)) + { + await File.WriteAllLinesAsync(rawDataDir, lastThreeDialogs); + } + else + { + await File.AppendAllLinesAsync(rawDataDir, lastThreeDialogs); + } } } }