Add converation completion hook.
This commit is contained in:
parent
63f3c6f184
commit
6b2d1fa30b
|
|
@ -1,5 +1,3 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
|
||||
namespace BotSharp.Abstraction.Agents;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
using BotSharp.Abstraction.Conversations.Models;
|
||||
|
||||
namespace BotSharp.Abstraction.Conversations;
|
||||
|
||||
public interface IConversationCompletionHook
|
||||
{
|
||||
Task BeforeCompletion(Agent agent, List<RoleDialogModel> conversations);
|
||||
Task<string> AfterCompletion(Agent agent, string response);
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
using BotSharp.Abstraction.Agents.Models;
|
||||
using BotSharp.Abstraction.Conversations.Models;
|
||||
|
||||
namespace BotSharp.Abstraction.MLTasks;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
global using System.ComponentModel.DataAnnotations;
|
||||
global using BotSharp.Abstraction.Agents.Models;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
<PackageReference Include="LLamaSharp" Version="0.4.0" />
|
||||
<PackageReference Include="LLamaSharp.Backend.Cuda11" Version="0.3.0" />
|
||||
<PackageReference Include="PdfPig" Version="0.1.8" />
|
||||
<PackageReference Include="TensorFlow.Keras" Version="0.11.0" />
|
||||
<PackageReference Include="TensorFlow.Keras" Version="0.11.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -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<IConversationCompletionHook>().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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
|
||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||
<PackageReference Include="System.Text.Json" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue