|
13 | 13 | using System.Runtime.InteropServices;
|
14 | 14 | using BotSharp.Abstraction.Agents;
|
15 | 15 | using System.IO;
|
| 16 | +using BotSharp.Abstraction.Routing.Settings; |
16 | 17 |
|
17 | 18 | namespace BotSharp.Plugin.RoutingSpeeder;
|
18 | 19 |
|
@@ -49,20 +50,26 @@ public override async Task BeforeCompletion(RoleDialogModel message)
|
49 | 50 |
|
50 | 51 | public override async Task AfterCompletion(RoleDialogModel message)
|
51 | 52 | {
|
52 |
| - // save train data |
53 |
| - var agentService = _services.CreateScope().ServiceProvider.GetRequiredService<IAgentService>(); |
54 |
| - var rootDataPath = agentService.GetDataDir(); |
| 53 | + var routerSettings = _services.GetRequiredService<RoutingSettings>(); |
| 54 | + bool saveFlag = (message.CurrentAgentId != routerSettings.RouterId) && (message.CurrentAgentId != routerSettings.ReasonerId); |
55 | 55 |
|
56 |
| - string rawDataDir = Path.Combine(rootDataPath, "raw_data", $"{message.CurrentAgentId}.txt"); |
57 |
| - var lastThreeDialogs = _dialogs.Where(x => x.Role == AgentRole.User).Select(x => x.Content).Reverse().Take(3).ToArray(); |
58 |
| - |
59 |
| - if (!File.Exists(rawDataDir)) |
60 |
| - { |
61 |
| - await File.WriteAllLinesAsync(rawDataDir, lastThreeDialogs); |
62 |
| - } |
63 |
| - else |
| 56 | + if (saveFlag) |
64 | 57 | {
|
65 |
| - await File.AppendAllLinesAsync(rawDataDir, lastThreeDialogs); |
| 58 | + // save train data |
| 59 | + var agentService = _services.CreateScope().ServiceProvider.GetRequiredService<IAgentService>(); |
| 60 | + var rootDataPath = agentService.GetDataDir(); |
| 61 | + |
| 62 | + string rawDataDir = Path.Combine(rootDataPath, "raw_data", $"{message.CurrentAgentId}.txt"); |
| 63 | + var lastThreeDialogs = _dialogs.Where(x => x.Role == AgentRole.User).Select(x => x.Content).Reverse().Take(3).ToArray(); |
| 64 | + |
| 65 | + if (!File.Exists(rawDataDir)) |
| 66 | + { |
| 67 | + await File.WriteAllLinesAsync(rawDataDir, lastThreeDialogs); |
| 68 | + } |
| 69 | + else |
| 70 | + { |
| 71 | + await File.AppendAllLinesAsync(rawDataDir, lastThreeDialogs); |
| 72 | + } |
66 | 73 | }
|
67 | 74 | }
|
68 | 75 | }
|
0 commit comments