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

43 lines
1.3 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 human being, customer service or customer representative.";
2023-10-16 20:07:07 +00:00
2023-10-20 03:47:14 +00:00
public List<NameDesc> Parameters => new List<NameDesc>
{
new NameDesc("reason", "why need customer service"),
2023-10-20 03:47:14 +00:00
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)
{
2023-10-16 20:07:07 +00:00
}
public async Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message)
2023-10-16 20:07:07 +00:00
{
message.Role = AgentRole.Assistant;
message.Content = inst.Response;
2023-10-16 20:07:07 +00:00
var hooks = _services.GetServices<IConversationHook>()
.OrderBy(x => x.Priority)
.ToList();
foreach (var hook in hooks)
{
await hook.OnHumanInterventionNeeded(message);
2023-10-16 20:07:07 +00:00
}
return true;
2023-10-16 20:07:07 +00:00
}
}