From d5ca93737600adce52184b3b31159b3685329e64 Mon Sep 17 00:00:00 2001
From: Jicheng Lu <103353@smsassist.com>
Date: Fri, 28 Jun 2024 11:29:43 -0500
Subject: [PATCH 1/2] add setting
---
.../Settings/ConversationSetting.cs | 1 +
.../BotSharp.Core/BotSharp.Core.csproj | 4 ---
.../Translation/TranslationService.cs | 27 +++++++++++++------
src/WebStarter/appsettings.json | 1 +
4 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs
index bbf5b9b1e..9df16428d 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 2bbaacc6f..51c73bd3d 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 399f9c0d4..f9aa73e3b 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 async Task Translate(Agent router, string messageId, T data, string
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();
+
+ foreach (var memory in memories)
+ {
+ map[memory.OriginalText] = memory.TranslatedText;
+ }
- var outOfMemoryList = queries.Where(x => !memoryHashes.Contains(x.HashText)).ToList();
+ 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 async Task Translate(Agent router, string messageId, T data, string
});
}
- _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 b5a151228..6439e25a2 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,
From 0c88bce00b0c3c6a603ea9421111485811f01b21 Mon Sep 17 00:00:00 2001
From: Jicheng Lu <103353@smsassist.com>
Date: Fri, 28 Jun 2024 11:58:19 -0500
Subject: [PATCH 2/2] rename file
---
src/Infrastructure/BotSharp.Core/Files/FilePlugin.cs | 2 +-
.../{AttachmentProcessingHook.cs => FileAnalyzerHook.cs} | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
rename src/Infrastructure/BotSharp.Core/Files/Hooks/{AttachmentProcessingHook.cs => FileAnalyzerHook.cs} (91%)
diff --git a/src/Infrastructure/BotSharp.Core/Files/FilePlugin.cs b/src/Infrastructure/BotSharp.Core/Files/FilePlugin.cs
index e549011b3..3110c8d5b 100644
--- a/src/Infrastructure/BotSharp.Core/Files/FilePlugin.cs
+++ b/src/Infrastructure/BotSharp.Core/Files/FilePlugin.cs
@@ -16,7 +16,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
{
services.AddScoped();
- services.AddScoped();
+ services.AddScoped();
services.AddScoped();
}
}
diff --git a/src/Infrastructure/BotSharp.Core/Files/Hooks/AttachmentProcessingHook.cs b/src/Infrastructure/BotSharp.Core/Files/Hooks/FileAnalyzerHook.cs
similarity index 91%
rename from src/Infrastructure/BotSharp.Core/Files/Hooks/AttachmentProcessingHook.cs
rename to src/Infrastructure/BotSharp.Core/Files/Hooks/FileAnalyzerHook.cs
index 8fc1c11d4..24c9b4f5c 100644
--- a/src/Infrastructure/BotSharp.Core/Files/Hooks/AttachmentProcessingHook.cs
+++ b/src/Infrastructure/BotSharp.Core/Files/Hooks/FileAnalyzerHook.cs
@@ -1,12 +1,12 @@
namespace BotSharp.Core.Files.Hooks;
-public class AttachmentProcessingHook : AgentHookBase
+public class FileAnalyzerHook : AgentHookBase
{
private static string TOOL_ASSISTANT = Guid.Empty.ToString();
public override string SelfId => string.Empty;
- public AttachmentProcessingHook(IServiceProvider services, AgentSettings settings)
+ public FileAnalyzerHook(IServiceProvider services, AgentSettings settings)
: base(services, settings)
{
}