|
1 | 1 | using BotSharp.Abstraction.Agents.Enums; |
2 | | -using BotSharp.Abstraction.Agents.Models; |
3 | 2 | using BotSharp.Abstraction.Conversations; |
4 | 3 | using BotSharp.Abstraction.Conversations.Models; |
5 | | -using BotSharp.Abstraction.MLTasks; |
6 | 4 | using Microsoft.Extensions.DependencyInjection; |
7 | 5 | using System; |
8 | 6 | using System.Linq; |
9 | 7 | using System.Threading.Tasks; |
10 | 8 | using BotSharp.Plugin.RoutingSpeeder.Settings; |
11 | 9 | using BotSharp.Abstraction.Templating; |
12 | 10 | using BotSharp.Plugin.RoutingSpeeder.Providers; |
13 | | -using System.Runtime.InteropServices; |
14 | 11 | using BotSharp.Abstraction.Agents; |
15 | 12 | using System.IO; |
16 | 13 | using BotSharp.Abstraction.Routing.Settings; |
@@ -59,16 +56,19 @@ public override async Task AfterCompletion(RoleDialogModel message) |
59 | 56 | var agentService = _services.CreateScope().ServiceProvider.GetRequiredService<IAgentService>(); |
60 | 57 | var rootDataPath = agentService.GetDataDir(); |
61 | 58 |
|
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(); |
| 59 | + string rawDataDir = Path.Combine(rootDataPath, "raw_data", $"agent.{message.CurrentAgentId}.txt"); |
| 60 | + var lastThreeDialogs = _dialogs.Where(x => x.Role == AgentRole.User || x.Role == AgentRole.Assistant) |
| 61 | + .Select(x => x.Content.Replace('\r', ' ').Replace('\n', ' ')) |
| 62 | + .TakeLast(3) |
| 63 | + .ToArray(); |
64 | 64 |
|
65 | 65 | if (!File.Exists(rawDataDir)) |
66 | 66 | { |
67 | | - await File.WriteAllLinesAsync(rawDataDir, lastThreeDialogs); |
| 67 | + await File.WriteAllTextAsync(rawDataDir, string.Join(' ', lastThreeDialogs)); |
68 | 68 | } |
69 | 69 | else |
70 | 70 | { |
71 | | - await File.AppendAllLinesAsync(rawDataDir, lastThreeDialogs); |
| 71 | + await File.AppendAllTextAsync(rawDataDir, string.Join(' ', lastThreeDialogs)); |
72 | 72 | } |
73 | 73 | } |
74 | 74 | } |
|
0 commit comments