Add filter when saving dialogue
This commit is contained in:
parent
7af506fc76
commit
e850381b9f
|
|
@ -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<IAgentService>();
|
||||
var rootDataPath = agentService.GetDataDir();
|
||||
var routerSettings = _services.GetRequiredService<RoutingSettings>();
|
||||
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<IAgentService>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue