BotSharp/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs
2024-10-18 23:04:33 +08:00

25 lines
716 B
C#

namespace BotSharp.Core.Routing;
public partial class RoutingService
{
public async Task<string> GetConversationContent(List<RoleDialogModel> dialogs, int maxDialogCount = 100)
{
var agentService = _services.GetRequiredService<IAgentService>();
var conversation = "";
foreach (var dialog in dialogs.TakeLast(maxDialogCount))
{
var role = dialog.Role;
if (role != AgentRole.User)
{
var agent = await agentService.GetAgent(dialog.CurrentAgentId);
role = agent.Name;
}
conversation += $"{role}: {dialog.Payload ?? dialog.Content}\r\n";
}
return conversation;
}
}