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;
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-28 20:59:26 +00:00
public List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>
2023-10-20 03:47:14 +00:00
{
2023-10-28 20:59:26 +00:00
new ParameterPropertyDef("reason", "why need customer service"),
new ParameterPropertyDef("response", "response content to user")
2023-10-20 03:47:14 +00:00
};
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
{
2023-10-30 16:48:18 +00:00
var response = new RoleDialogModel(AgentRole.Assistant, inst.Response)
{
CurrentAgentId = message.CurrentAgentId,
MessageId = message.MessageId,
StopCompletion = true,
FunctionName = inst.Function
};
_dialogs.Add(response);
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-30 16:48:18 +00:00
await hook.OnHumanInterventionNeeded(response);
2023-10-16 20:07:07 +00:00
}
return true;
2023-10-16 20:07:07 +00:00
}
}