diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs index bbf5b9b1..9df16428 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs @@ -11,6 +11,7 @@ public class ConversationSetting public bool EnableExecutionLog { get; set; } public bool EnableContentLog { get; set; } public bool EnableStateLog { get; set; } + public bool EnableTranslationMemory { get; set; } public CleanConversationSetting CleanSetting { get; set; } = new CleanConversationSetting(); public RateLimitSetting RateLimit { get; set; } = new RateLimitSetting(); } diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 2bbaacc6..51c73bd3 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -188,8 +188,4 @@ - - - - diff --git a/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs b/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs index 399f9c0d..f9aa73e3 100644 --- a/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs +++ b/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs @@ -13,6 +13,7 @@ public class TranslationService : ITranslationService { private readonly IServiceProvider _services; private readonly IBotSharpRepository _db; + private readonly ConversationSetting _convSettings; private readonly ILogger _logger; private readonly BotSharpOptions _options; private Agent _router; @@ -22,11 +23,13 @@ public class TranslationService : ITranslationService public TranslationService( IServiceProvider services, IBotSharpRepository db, + ConversationSetting convSettings, ILogger logger, BotSharpOptions options) { _services = services; _db = db; + _convSettings = convSettings; _logger = logger; _options = options; } @@ -69,18 +72,23 @@ public class TranslationService : ITranslationService HashText = Utilities.HashTextSha256(x), Language = language }).ToList(); - var memories = _db.GetTranslationMemories(queries); - var memoryHashes = memories.Select(x => x.HashText).ToList(); + var outOfMemoryList = queries; - foreach (var memory in memories) + if (_convSettings.EnableTranslationMemory) { - map[memory.OriginalText] = memory.TranslatedText; - } + var memories = _db.GetTranslationMemories(queries); + var memoryHashes = memories.Select(x => x.HashText).ToList(); - var outOfMemoryList = queries.Where(x => !memoryHashes.Contains(x.HashText)).ToList(); + foreach (var memory in memories) + { + map[memory.OriginalText] = memory.TranslatedText; + } + + outOfMemoryList = queries.Where(x => !memoryHashes.Contains(x.HashText)).ToList(); + } #endregion - var texts = outOfMemoryList.ToArray() + var texts = outOfMemoryList .Select((text, i) => new TranslationInput { Id = i + 1, @@ -123,7 +131,10 @@ public class TranslationService : ITranslationService }); } - _db.SaveTranslationMemories(memoryInputs); + if (_convSettings.EnableTranslationMemory) + { + _db.SaveTranslationMemories(memoryInputs); + } } clonedData = Assign(clonedData, map); diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index b5a15122..6439e25a 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -136,6 +136,7 @@ "EnableExecutionLog": true, "EnableContentLog": true, "EnableStateLog": true, + "EnableTranslationMemory": false, "CleanSetting": { "Enable": true, "BatchSize": 50,