update language detection

This commit is contained in:
Joanna Ren 2024-04-23 17:13:38 -05:00
parent de23377782
commit ab3c6089a6
4 changed files with 13 additions and 4 deletions

View file

@ -23,7 +23,7 @@ public class ResponseToUserRoutingHandler : RoutingHandlerBase, IRoutingHandler
new ParameterPropertyDef("user_message_in_english",
"Translate user message from non-English to English"),
new ParameterPropertyDef("language",
"Language detected based on the latest message that USER sent, could be English, Spanish or Chinese.",
"User prefered language, considering the whole conversation. Language could be English, Spanish or Chinese.",
required: true),
};

View file

@ -32,7 +32,7 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
new ParameterPropertyDef("user_message_in_english",
"Translate user message from non-English to English"),
new ParameterPropertyDef("language",
"Language detected based on the latest message that USER sent, could be English, Spanish or Chinese.",
"User prefered language, considering the whole conversation. Language could be English, Spanish or Chinese.",
required: true),
};

View file

@ -1,6 +1,7 @@
using Amazon.Runtime.Internal.Transform;
using BotSharp.Abstraction.Options;
using BotSharp.Abstraction.Templating;
using BotSharp.Abstraction.Translation;
using BotSharp.Abstraction.Translation.Attributes;
using Newtonsoft.Json;
using System.Reflection;
@ -28,16 +29,23 @@ public class TranslationService : ITranslationService
{
_router = router;
_messageId = messageId;
var unique = new HashSet<string>();
Collect(data, ref unique);
if (unique.Count == 0)
{
return data;
}
var cloned = data;
if (clone)
{
cloned = Clone(data);
}
var unique = new HashSet<string>();
Collect(cloned, ref unique);
var map = await InnerTranslate(unique, language);
cloned = Assign(cloned, map);
return cloned;
}

View file

@ -10,3 +10,4 @@ Expected user goal agent is {{ expected_user_goal_agent }}.
{%- else -%}
User goal agent is inferred based on user initial request.
{%- endif %}
Detect language based on the overall content in [CONVERSATION] and only include user message.