Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public async Task<string> RenderFunctionResponse(string agentId, RoleDialogModel
// Find response template
var agentService = _services.GetRequiredService<IAgentService>();
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
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;
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;
Expand Down Expand Up @@ -59,16 +56,19 @@ public override async Task AfterCompletion(RoleDialogModel message)
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();
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));
}
}
}
Expand Down