Fix OnPlanningCompleted hook
This commit is contained in:
parent
147ec7662e
commit
1c53cb605e
|
|
@ -4,7 +4,7 @@ namespace BotSharp.Core.Infrastructures;
|
|||
|
||||
public static class HookEmitter
|
||||
{
|
||||
public static async Task<HookEmittedResult> Emit<T>(IServiceProvider services, Action<T> action)
|
||||
public static HookEmittedResult Emit<T>(IServiceProvider services, Action<T> action)
|
||||
{
|
||||
var logger = services.GetRequiredService<ILogger<T>>();
|
||||
var result = new HookEmittedResult();
|
||||
|
|
@ -25,4 +25,26 @@ public static class HookEmitter
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<HookEmittedResult> Emit<T>(IServiceProvider services, Func<T, Task> action)
|
||||
{
|
||||
var logger = services.GetRequiredService<ILogger<T>>();
|
||||
var result = new HookEmittedResult();
|
||||
var hooks = services.GetServices<T>();
|
||||
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"Emit hook action on {action.Method.Name}({hook.GetType().Name})");
|
||||
await action(hook);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,8 +67,9 @@ public class SummaryPlanFn : IFunctionCallback
|
|||
var summary = await GetAiResponse(plannerAgent);
|
||||
message.Content = summary.Content;
|
||||
|
||||
await HookEmitter.Emit<IPlanningHook>(_services, x =>
|
||||
x.OnPlanningCompleted(nameof(TwoStageTaskPlanner), message));
|
||||
await HookEmitter.Emit<IPlanningHook>(_services, async hook =>
|
||||
await hook.OnPlanningCompleted(nameof(TwoStageTaskPlanner), message)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue