diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index be1f0b6a..df13cd24 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs @@ -1,5 +1,3 @@ -using BotSharp.Abstraction.Agents.Models; - namespace BotSharp.Abstraction.Agents; /// diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationCompletionHook.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationCompletionHook.cs new file mode 100644 index 00000000..be68b6d6 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationCompletionHook.cs @@ -0,0 +1,9 @@ +using BotSharp.Abstraction.Conversations.Models; + +namespace BotSharp.Abstraction.Conversations; + +public interface IConversationCompletionHook +{ + Task BeforeCompletion(Agent agent, List conversations); + Task AfterCompletion(Agent agent, string response); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs b/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs index c7808ce4..00ef6c7e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs +++ b/src/Infrastructure/BotSharp.Abstraction/MLTasks/IChatCompletion.cs @@ -1,4 +1,3 @@ -using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Conversations.Models; namespace BotSharp.Abstraction.MLTasks; diff --git a/src/Infrastructure/BotSharp.Abstraction/Using.cs b/src/Infrastructure/BotSharp.Abstraction/Using.cs index fd772925..6a73f3ff 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Using.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Using.cs @@ -2,4 +2,5 @@ global using System; global using System.Collections.Generic; global using System.Text; global using System.Threading.Tasks; -global using System.ComponentModel.DataAnnotations; \ No newline at end of file +global using System.ComponentModel.DataAnnotations; +global using BotSharp.Abstraction.Agents.Models; \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 9e348243..4f5e5df0 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -67,7 +67,7 @@ - + diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index f0a994e9..5f5c1d33 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -90,8 +90,20 @@ public class ConversationService : IConversationService } var chatCompletion = GetChatCompletion(); - var response = await chatCompletion.GetChatCompletionsAsync(agent, wholeDialogs); + + // Before chat completion hook + var hooks = _services.GetServices().ToList(); + + hooks.ForEach(hook => hook.BeforeCompletion(agent, wholeDialogs)); + var response = await chatCompletion.GetChatCompletionsAsync(agent, wholeDialogs); + + // After chat completion hook + hooks.ForEach(async hook => + { + response = await hook.AfterCompletion(agent, response); + }); + return response; } diff --git a/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj b/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj index 2bbca3fb..f6f00297 100644 --- a/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj +++ b/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -8,7 +8,7 @@ - +