optimize translation
This commit is contained in:
parent
ceca3d8963
commit
b30aa58aa6
|
|
@ -144,30 +144,6 @@ public partial class RoutingService : IRoutingService
|
||||||
loopCount++;
|
loopCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle multi-language for output
|
|
||||||
if (language != LanguageType.UNKNOWN && language != LanguageType.ENGLISH)
|
|
||||||
{
|
|
||||||
if (response.RichContent != null)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(response.RichContent.Message.Text))
|
|
||||||
{
|
|
||||||
response.RichContent.Message.Text = response.Content;
|
|
||||||
}
|
|
||||||
|
|
||||||
response.SecondaryRichContent = await translator.Translate(_router,
|
|
||||||
message.MessageId,
|
|
||||||
response.RichContent,
|
|
||||||
language: language);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
response.SecondaryContent = await translator.Translate(_router,
|
|
||||||
message.MessageId,
|
|
||||||
response.Content,
|
|
||||||
language: language);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ public static class BotSharpLoggerExtensions
|
||||||
services.AddScoped<IContentGeneratingHook, TokenStatsConversationHook>();
|
services.AddScoped<IContentGeneratingHook, TokenStatsConversationHook>();
|
||||||
services.AddScoped<IContentGeneratingHook, VerboseLogHook>();
|
services.AddScoped<IContentGeneratingHook, VerboseLogHook>();
|
||||||
services.AddScoped<IConversationHook, RateLimitConversationHook>();
|
services.AddScoped<IConversationHook, RateLimitConversationHook>();
|
||||||
|
services.AddScoped<IConversationHook, TranslationResponseHook>();
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
using BotSharp.Abstraction.Agents;
|
||||||
|
using BotSharp.Abstraction.Infrastructures.Enums;
|
||||||
|
using BotSharp.Abstraction.Translation;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace BotSharp.Logger.Hooks
|
||||||
|
{
|
||||||
|
public class TranslationResponseHook : ConversationHookBase
|
||||||
|
{
|
||||||
|
private readonly IServiceProvider _services;
|
||||||
|
private readonly IConversationStateService _states;
|
||||||
|
private const string LessenCopilot = "2cd4b805-7078-4405-87e9-2ec9aadf8a11";
|
||||||
|
|
||||||
|
public TranslationResponseHook(IServiceProvider services,
|
||||||
|
IConversationStateService states)
|
||||||
|
{
|
||||||
|
_services = services;
|
||||||
|
_states = states;
|
||||||
|
}
|
||||||
|
public override async Task OnResponseGenerated(RoleDialogModel message)
|
||||||
|
{
|
||||||
|
// Handle multi-language for output
|
||||||
|
var agentService = _services.GetRequiredService<IAgentService>();
|
||||||
|
var router = await agentService.LoadAgent(LessenCopilot);
|
||||||
|
var translator = _services.GetRequiredService<ITranslationService>();
|
||||||
|
var language = _states.GetState("language", LanguageType.ENGLISH);
|
||||||
|
if (language != LanguageType.UNKNOWN && language != LanguageType.ENGLISH)
|
||||||
|
{
|
||||||
|
if (message.RichContent != null)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(message.RichContent.Message.Text))
|
||||||
|
{
|
||||||
|
message.RichContent.Message.Text = message.Content;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.SecondaryRichContent = await translator.Translate(router,
|
||||||
|
message.MessageId,
|
||||||
|
message.RichContent,
|
||||||
|
language: language);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message.SecondaryContent = await translator.Translate(router,
|
||||||
|
message.MessageId,
|
||||||
|
message.Content,
|
||||||
|
language: language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await base.OnResponseGenerated(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue