ChatHubConversationHook priority
This commit is contained in:
parent
ba855bc7cc
commit
1e974441ff
|
|
@ -2,27 +2,23 @@ namespace BotSharp.Abstraction.Conversations;
|
|||
|
||||
public abstract class ConversationHookBase : IConversationHook
|
||||
{
|
||||
protected Agent _agent;
|
||||
public Agent Agent => _agent;
|
||||
public Agent Agent { get; private set; }
|
||||
|
||||
protected Conversation _conversation;
|
||||
public Conversation Conversation => _conversation;
|
||||
public Conversation Conversation { get; private set; }
|
||||
|
||||
protected List<RoleDialogModel> _dialogs;
|
||||
public List<RoleDialogModel> Dialogs => _dialogs;
|
||||
public List<RoleDialogModel> Dialogs { get; private set; }
|
||||
|
||||
protected int _priority = 0;
|
||||
public int Priority => _priority;
|
||||
public int Priority { get; protected set; } = 0;
|
||||
|
||||
public IConversationHook SetAgent(Agent agent)
|
||||
{
|
||||
_agent = agent;
|
||||
Agent = agent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IConversationHook SetConversation(Conversation conversation)
|
||||
{
|
||||
_conversation = conversation;
|
||||
Conversation = conversation;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +33,7 @@ public abstract class ConversationHookBase : IConversationHook
|
|||
|
||||
public virtual Task OnDialogsLoaded(List<RoleDialogModel> dialogs)
|
||||
{
|
||||
_dialogs = dialogs;
|
||||
Dialogs = dialogs;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public partial class ConversationService
|
|||
var dialogs = conv.GetDialogHistory();
|
||||
|
||||
var statistics = _services.GetRequiredService<ITokenStatistics>();
|
||||
var hooks = _services.GetServices<IConversationHook>().ToList();
|
||||
var hookProvider = _services.GetRequiredService<ConversationHookProvider>();
|
||||
|
||||
RoleDialogModel response = message;
|
||||
bool stopCompletion = false;
|
||||
|
|
@ -44,9 +44,7 @@ public partial class ConversationService
|
|||
message.Payload = replyMessage.Payload;
|
||||
}
|
||||
|
||||
// Before chat completion hook
|
||||
hooks = ReOrderConversationHooks(hooks);
|
||||
foreach (var hook in hooks)
|
||||
foreach (var hook in hookProvider.HooksOrderByPriority)
|
||||
{
|
||||
hook.SetAgent(agent)
|
||||
.SetConversation(conversation);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class ChatHubConversationHook : ConversationHookBase
|
|||
_chatHub = chatHub;
|
||||
_user = user;
|
||||
_options = options;
|
||||
Priority = -1; // Make sure this hook is the top one.
|
||||
}
|
||||
|
||||
public override async Task OnConversationInitialized(Conversation conversation)
|
||||
|
|
|
|||
Loading…
Reference in a new issue