2023-09-22 20:38:58 +00:00
|
|
|
using BotSharp.Abstraction.Functions.Models;
|
2023-10-20 03:47:14 +00:00
|
|
|
using BotSharp.Abstraction.Models;
|
2023-09-22 20:38:58 +00:00
|
|
|
using BotSharp.Abstraction.Routing;
|
|
|
|
|
using BotSharp.Abstraction.Routing.Settings;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.Core.Routing.Handlers;
|
|
|
|
|
|
|
|
|
|
public class ConversationEndRoutingHandler : RoutingHandlerBase, IRoutingHandler
|
|
|
|
|
{
|
|
|
|
|
public string Name => "conversation_end";
|
|
|
|
|
|
2023-10-13 23:36:57 +00:00
|
|
|
public string Description => "User completed his task and wants to end the conversation.";
|
2023-09-22 20:38:58 +00:00
|
|
|
|
|
|
|
|
public bool IsReasoning => false;
|
|
|
|
|
|
2023-10-20 03:47:14 +00:00
|
|
|
public List<NameDesc> Parameters => new List<NameDesc>
|
|
|
|
|
{
|
|
|
|
|
new NameDesc("reason", "why end conversation"),
|
|
|
|
|
new NameDesc("response", "response content to user")
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-22 20:38:58 +00:00
|
|
|
public ConversationEndRoutingHandler(IServiceProvider services, ILogger<ConversationEndRoutingHandler> logger, RoutingSettings settings)
|
|
|
|
|
: base(services, logger, settings)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 20:08:59 +00:00
|
|
|
public async Task<RoleDialogModel> Handle(IRoutingService routing, FunctionCallFromLlm inst)
|
2023-09-22 20:38:58 +00:00
|
|
|
{
|
2023-10-13 23:36:57 +00:00
|
|
|
var result = new RoleDialogModel(AgentRole.Assistant, inst.Response)
|
2023-10-13 20:08:59 +00:00
|
|
|
{
|
|
|
|
|
CurrentAgentId = _settings.RouterId,
|
|
|
|
|
FunctionName = inst.Function,
|
2023-10-13 23:36:57 +00:00
|
|
|
ExecutionData = inst
|
2023-10-13 20:08:59 +00:00
|
|
|
};
|
2023-10-16 00:08:24 +00:00
|
|
|
|
|
|
|
|
var hooks = _services.GetServices<IConversationHook>()
|
|
|
|
|
.OrderBy(x => x.Priority)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var hook in hooks)
|
|
|
|
|
{
|
2023-10-16 20:07:07 +00:00
|
|
|
await hook.ConversationEnding(result);
|
2023-10-16 00:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-13 20:08:59 +00:00
|
|
|
return result;
|
2023-09-22 20:38:58 +00:00
|
|
|
}
|
|
|
|
|
}
|