Merge pull request #518 from iceljc/features/add-translation-memory-settings
add translation memory setting
This commit is contained in:
commit
9162e8156e
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,8 +188,4 @@
|
|||
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Translation\Models\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class FilePlugin : IBotSharpPlugin
|
|||
{
|
||||
services.AddScoped<IBotSharpFileService, BotSharpFileService>();
|
||||
|
||||
services.AddScoped<IAgentHook, AttachmentProcessingHook>();
|
||||
services.AddScoped<IAgentHook, FileAnalyzerHook>();
|
||||
services.AddScoped<IAgentToolHook, FileAnalyzerToolHook>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ public class TranslationService : ITranslationService
|
|||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IBotSharpRepository _db;
|
||||
private readonly ConversationSetting _convSettings;
|
||||
private readonly ILogger<TranslationService> _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<TranslationService> 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);
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@
|
|||
"EnableExecutionLog": true,
|
||||
"EnableContentLog": true,
|
||||
"EnableStateLog": true,
|
||||
"EnableTranslationMemory": false,
|
||||
"CleanSetting": {
|
||||
"Enable": true,
|
||||
"BatchSize": 50,
|
||||
|
|
|
|||
Loading…
Reference in a new issue