BotSharp/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2023-10-16 20:07:07 +00:00
using BotSharp.Abstraction.Functions.Models;
2023-10-20 03:47:14 +00:00
using BotSharp.Abstraction.Models;
2023-10-16 20:07:07 +00:00
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Routing.Settings;
namespace BotSharp.Core.Routing.Handlers;
public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandler
{
public string Name => "human_intervention_needed";
public string Description => "Reach out to a real human or customer representative.";
private readonly RoutingSettings _settings;
2023-10-20 03:47:14 +00:00
public List<NameDesc> Parameters => new List<NameDesc>
{
new NameDesc("reason", "why need customer service representative (human being)"),
new NameDesc("response", "response content to user")
};
2023-10-16 20:07:07 +00:00
public HumanInterventionNeededHandler(IServiceProvider services, ILogger<HumanInterventionNeededHandler> logger, RoutingSettings settings)
: base(services, logger, settings)
{
_settings = settings;
}
public async Task<RoleDialogModel> Handle(IRoutingService routing, FunctionCallFromLlm inst)
{
var result = new RoleDialogModel(AgentRole.Assistant, inst.Response)
{
CurrentAgentId = _settings.RouterId,
FunctionName = inst.Function,
2023-10-23 00:31:49 +00:00
Data = inst
2023-10-16 20:07:07 +00:00
};
var hooks = _services.GetServices<IConversationHook>()
.OrderBy(x => x.Priority)
.ToList();
foreach (var hook in hooks)
{
2023-10-23 00:31:49 +00:00
await hook.OnHumanInterventionNeeded(result);
2023-10-16 20:07:07 +00:00
}
return result;
}
}