refine instruction log settings
This commit is contained in:
parent
b2e6db6999
commit
52e6c6a4b0
|
|
@ -8,16 +8,16 @@ public class InstructHookBase : IInstructHook
|
|||
|
||||
public virtual async Task BeforeCompletion(Agent agent, RoleDialogModel message)
|
||||
{
|
||||
return;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual async Task AfterCompletion(Agent agent, InstructResult result)
|
||||
{
|
||||
return;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual async Task OnResponseGenerated(InstructResponseModel response)
|
||||
{
|
||||
return;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,11 @@ namespace BotSharp.Abstraction.Instructs.Settings;
|
|||
|
||||
public class InstructionSettings
|
||||
{
|
||||
public bool EnableLog { get; set; }
|
||||
public InstructionLogSetting Logging { get; set; } = new();
|
||||
}
|
||||
|
||||
public class InstructionLogSetting
|
||||
{
|
||||
public bool Enabled { get; set; } = true;
|
||||
public List<string> ExcludedAgentIds { get; set; } = [];
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Loggers.Models;
|
|||
public class InstructionLogModel
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string Id { get; set; } = default!;
|
||||
|
||||
[JsonPropertyName("agent_id")]
|
||||
|
|
|
|||
|
|
@ -26,7 +26,14 @@ public class InstructionLogHook : InstructHookBase
|
|||
public override async Task OnResponseGenerated(InstructResponseModel response)
|
||||
{
|
||||
var settings = _services.GetRequiredService<InstructionSettings>();
|
||||
if (!settings.EnableLog || response == null) return;
|
||||
if (response == null
|
||||
|| string.IsNullOrWhiteSpace(response.AgentId)
|
||||
|| settings == null
|
||||
|| !settings.Logging.Enabled
|
||||
|| settings.Logging.ExcludedAgentIds.Contains(response.AgentId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
|
|
@ -49,6 +56,7 @@ public class InstructionLogHook : InstructHookBase
|
|||
UserId = user?.Id
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
||||
await base.OnResponseGenerated(response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,7 +223,10 @@
|
|||
},
|
||||
|
||||
"Instruction": {
|
||||
"EnableLog": true
|
||||
"Logging": {
|
||||
"Enabled": true,
|
||||
"ExcludedAgentIds": []
|
||||
}
|
||||
},
|
||||
|
||||
"ChatHub": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue