From adc6486345fe53bd20d8d40b565fe32d9140f1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Wed, 22 May 2024 14:53:36 +0800 Subject: [PATCH 1/2] Update TranslationService.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hotfix json escaped question error: [ERR] [] '<' is not a hex digit following '\u' within a JSON string. The string should be correctly escaped. Path: $.texts[0].text | LineNumber: 0 | BytePositionInLine: 411. json: {"input_lang":"English", "output_count":3, "output_lang":"Spanish", "texts":[{"id":1,"text":"Aquí hay un resumen de los horarios que ha indicado que está disponible. Las fechas no están confirmadas. El técnico revisará y se pondrá en contacto para programar.\u003Cp\u003E\u003Cb\u003EJueves, 23 de mayo de 2024\u003C/b\u003E\u003C/br\u003ETodo el día (08:00 AM - 08:00 PM)\u003C/p\u003E\u003Cp\u003E\u003Viernes, 24 de mayo de 2024\u003C/b\u003E\u003C/br\u003EMañana (08:00 AM - 01:00 PM)\u003C/p\u003E\u003Cp\u003E\u003Lunes, 27 de mayo de 2024\u003C/b\u003E\u003C/br\u003ETarde (01:00 PM - 08:00 PM)\u003C/p\u003E"},{"id":2,"text":"Se ve bien"},{"id":3,"text":"Empezar de nuevo"}]} --- .../BotSharp.Core/Translation/TranslationService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs b/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs index 44bb22a82..7067eb7ea 100644 --- a/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs +++ b/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs @@ -310,7 +310,8 @@ private T Assign(T data, Dictionary map) where T : class /// private async Task InnerTranslate(List texts, string language, string template) { - var jsonString = JsonSerializer.Serialize(texts); + var options = new JsonSerializerOptions() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; + var jsonString = JsonSerializer.Serialize(texts, options); var translator = new Agent { Id = Guid.Empty.ToString(), From 6f8c840dcd273ded0c03d237efef2c0a4369602d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=93=E7=A3=8A?= Date: Wed, 22 May 2024 15:08:13 +0800 Subject: [PATCH 2/2] Update translation_prompt.liquid optimize translation prompt 1.Enrich the translation examples. 2.Add necessary validation conditions for "output_count". --- .../templates/translation_prompt.liquid | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/translation_prompt.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/translation_prompt.liquid index 3d33375b7..6b3a8677e 100644 --- a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/translation_prompt.liquid +++ b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/translation_prompt.liquid @@ -2,4 +2,5 @@ ===== Translate all the above sentences into {{ language }}. -Output the translated text in JSON {"input_lang":"original text language", "output_count": {{ text_list_size }}, "output_lang":"{{ language }}", "texts":[{"id": 1, "text":""}]}. +Output the translated text in JSON {"input_lang":"original text language", "output_count": {{ text_list_size }}, "output_lang":"{{ language }}", "texts":[{"id": 1, "text":""},{"id": 2, "text":""}]}. +The "output_count" must equal the length of the "texts" array in the output.