Skip to content

Commit aa3fd24

Browse files
authored
Merge pull request #129 from hchen2020/master
Fix collecting training data set.
2 parents 6146ca1 + fee9b6f commit aa3fd24

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public async Task<string> RenderFunctionResponse(string agentId, RoleDialogModel
2020
// Find response template
2121
var agentService = _services.GetRequiredService<IAgentService>();
2222
var dir = Path.Combine(agentService.GetAgentDataDir(agentId), "responses");
23+
if (!Directory.Exists(dir))
24+
{
25+
return string.Empty;
26+
}
27+
2328
var responses = Directory.GetFiles(dir)
2429
.Where(f => f.Split(Path.DirectorySeparatorChar).Last().Split('.')[1] == message.FunctionName)
2530
.ToList();

src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
using BotSharp.Abstraction.Agents.Enums;
2-
using BotSharp.Abstraction.Agents.Models;
32
using BotSharp.Abstraction.Conversations;
43
using BotSharp.Abstraction.Conversations.Models;
5-
using BotSharp.Abstraction.MLTasks;
64
using Microsoft.Extensions.DependencyInjection;
75
using System;
86
using System.Linq;
97
using System.Threading.Tasks;
108
using BotSharp.Plugin.RoutingSpeeder.Settings;
119
using BotSharp.Abstraction.Templating;
1210
using BotSharp.Plugin.RoutingSpeeder.Providers;
13-
using System.Runtime.InteropServices;
1411
using BotSharp.Abstraction.Agents;
1512
using System.IO;
1613
using BotSharp.Abstraction.Routing.Settings;
@@ -59,16 +56,19 @@ public override async Task AfterCompletion(RoleDialogModel message)
5956
var agentService = _services.CreateScope().ServiceProvider.GetRequiredService<IAgentService>();
6057
var rootDataPath = agentService.GetDataDir();
6158

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();
6464

6565
if (!File.Exists(rawDataDir))
6666
{
67-
await File.WriteAllLinesAsync(rawDataDir, lastThreeDialogs);
67+
await File.WriteAllTextAsync(rawDataDir, string.Join(' ', lastThreeDialogs));
6868
}
6969
else
7070
{
71-
await File.AppendAllLinesAsync(rawDataDir, lastThreeDialogs);
71+
await File.AppendAllTextAsync(rawDataDir, string.Join(' ', lastThreeDialogs));
7272
}
7373
}
7474
}

0 commit comments

Comments
 (0)