diff --git a/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs b/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs index cac30ff7..f2b26495 100644 --- a/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs +++ b/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs @@ -20,6 +20,11 @@ public class ResponseTemplateService : IResponseTemplateService // Find response template var agentService = _services.GetRequiredService(); var dir = Path.Combine(agentService.GetAgentDataDir(agentId), "responses"); + if (!Directory.Exists(dir)) + { + return string.Empty; + } + var responses = Directory.GetFiles(dir) .Where(f => f.Split(Path.DirectorySeparatorChar).Last().Split('.')[1] == message.FunctionName) .ToList(); diff --git a/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs b/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs index 869afe94..4584f371 100644 --- a/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs +++ b/src/Plugins/BotSharp.Plugin.RoutingSpeeder/RoutingConversationHook.cs @@ -1,8 +1,6 @@ using BotSharp.Abstraction.Agents.Enums; -using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Conversations.Models; -using BotSharp.Abstraction.MLTasks; using Microsoft.Extensions.DependencyInjection; using System; using System.Linq; @@ -10,7 +8,6 @@ using System.Threading.Tasks; 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; using BotSharp.Abstraction.Routing.Settings; @@ -59,16 +56,19 @@ public class RoutingConversationHook: ConversationHookBase var agentService = _services.CreateScope().ServiceProvider.GetRequiredService(); 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(); + string rawDataDir = Path.Combine(rootDataPath, "raw_data", $"agent.{message.CurrentAgentId}.txt"); + var lastThreeDialogs = _dialogs.Where(x => x.Role == AgentRole.User || x.Role == AgentRole.Assistant) + .Select(x => x.Content.Replace('\r', ' ').Replace('\n', ' ')) + .TakeLast(3) + .ToArray(); if (!File.Exists(rawDataDir)) { - await File.WriteAllLinesAsync(rawDataDir, lastThreeDialogs); + await File.WriteAllTextAsync(rawDataDir, string.Join(' ', lastThreeDialogs)); } else { - await File.AppendAllLinesAsync(rawDataDir, lastThreeDialogs); + await File.AppendAllTextAsync(rawDataDir, string.Join(' ', lastThreeDialogs)); } } }