BotSharp/src/Infrastructure/BotSharp.Core/Evaluations/ExecutionLogger.cs

27 lines
844 B
C#
Raw Normal View History

2023-10-23 00:31:49 +00:00
using BotSharp.Abstraction.Evaluations;
using BotSharp.Abstraction.Repositories;
2023-10-24 21:38:34 +00:00
using System.Text.RegularExpressions;
2023-10-23 00:31:49 +00:00
namespace BotSharp.Core.Evaluations;
public class ExecutionLogger : IExecutionLogger
{
private readonly BotSharpDatabaseSettings _dbSettings;
private readonly IServiceProvider _services;
public ExecutionLogger(
BotSharpDatabaseSettings dbSettings,
IServiceProvider services)
{
_dbSettings = dbSettings;
_services = services;
}
public void Append(string conversationId, string content)
{
2023-10-24 21:38:34 +00:00
content = content.Replace("\r\n", " ").Replace("\n", " ");
content = Regex.Replace(content, @"\s+", " ");
2023-10-23 20:33:24 +00:00
var db = _services.GetRequiredService<IBotSharpRepository>();
2023-11-29 16:21:03 +00:00
db.AddExecutionLogs(conversationId, new List<string> { content });
2023-10-23 00:31:49 +00:00
}
}