From 2147d69ecf433638cb8c3388ab3ad295a792a7df Mon Sep 17 00:00:00 2001
From: Haiping Chen <101423@smsassist.com>
Date: Mon, 20 May 2024 21:13:12 -0500
Subject: [PATCH] translation improvement.
---
.../BotSharp.Core/Translation/TranslationService.cs | 5 +----
.../templates/translation_prompt.liquid | 4 ++--
.../Controllers/ConversationController.cs | 9 +--------
3 files changed, 4 insertions(+), 14 deletions(-)
diff --git a/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs b/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs
index ff28b4e6..5c60e108 100644
--- a/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs
+++ b/src/Infrastructure/BotSharp.Core/Translation/TranslationService.cs
@@ -302,10 +302,7 @@ public class TranslationService : ITranslationService
///
private async Task InnerTranslate(List texts, string language, string template)
{
- var jsonString = JsonSerializer.Serialize(texts, new JsonSerializerOptions
- {
- WriteIndented = true,
- }) ;
+ var jsonString = JsonSerializer.Serialize(texts);
var translator = new Agent
{
Id = Guid.Empty.ToString(),
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 7403130c..3d33375b 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
@@ -1,5 +1,5 @@
{{ text_list }}
=====
-Translate the above sentences into {{ language }}.
-Output the translated text in JSON {"input_lang":"original text language", "output_lang":"{{ language }}", "texts":[""]}.
+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":""}]}.
diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs
index 34095acf..a1d2ca3e 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs
@@ -1,6 +1,4 @@
using BotSharp.Abstraction.Routing;
-using Newtonsoft.Json.Serialization;
-using Newtonsoft.Json;
namespace BotSharp.OpenAPI.Controllers;
@@ -303,12 +301,7 @@ public class ConversationController : ControllerBase
private async Task OnChunkReceived(HttpResponse response, RoleDialogModel message)
{
- var json = JsonConvert.SerializeObject(message, new JsonSerializerSettings
- {
- Formatting = Formatting.None,
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- NullValueHandling = NullValueHandling.Ignore,
- });
+ var json = JsonSerializer.Serialize(message);
var buffer = Encoding.UTF8.GetBytes($"data:{json}\n");
await response.Body.WriteAsync(buffer, 0, buffer.Length);