Merge pull request #125 from evan-cao-wb/Add-confidence-threshold

Add async save user dialogue data
This commit is contained in:
Haiping 2023-09-01 13:50:34 -05:00 committed by GitHub
commit 24898ff108
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,8 @@ using BotSharp.Plugin.RoutingSpeeder.Settings;
using BotSharp.Abstraction.Templating;
using BotSharp.Plugin.RoutingSpeeder.Providers;
using System.Runtime.InteropServices;
using BotSharp.Abstraction.Agents;
using System.IO;
namespace BotSharp.Plugin.RoutingSpeeder;
@ -44,4 +46,23 @@ public class RoutingConversationHook: ConversationHookBase
message.StopCompletion = true;
}
}
public override async Task AfterCompletion(RoleDialogModel message)
{
// save train data
var agentService = _services.CreateScope().ServiceProvider.GetRequiredService<IAgentService>();
var rootDataPath = agentService.GetDataDir();
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);
}
}
}