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

49 lines
1.5 KiB
C#
Raw Normal View History

2023-09-22 20:38:58 +00:00
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Routing.Settings;
namespace BotSharp.Core.Routing.Handlers;
public class ConversationEndRoutingHandler : RoutingHandlerBase, IRoutingHandler
{
public string Name => "conversation_end";
public string Description => "User completed his task and wants to end the conversation.";
2023-09-22 20:38:58 +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 end conversation"),
new ParameterPropertyDef("response", "response content to user")
2023-10-20 03:47:14 +00:00
};
2023-09-22 20:38:58 +00:00
public ConversationEndRoutingHandler(IServiceProvider services, ILogger<ConversationEndRoutingHandler> logger, RoutingSettings settings)
: base(services, logger, settings)
{
}
public async Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message)
2023-09-22 20:38:58 +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);
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.OnConversationEnding(response);
}
return true;
2023-09-22 20:38:58 +00:00
}
}