Skip to content

Commit e076d0f

Browse files
committed
Encoding support for non-English string response
1 parent c1ee29f commit e076d0f

File tree

1 file changed

+10
-4
lines changed
  • App/backend-api/Microsoft.GS.DPS/API/ChatHost

1 file changed

+10
-4
lines changed

App/backend-api/Microsoft.GS.DPS/API/ChatHost/ChatHost.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.GS.DPS.Model.ChatHost;
1+
using Microsoft.GS.DPS.Model.ChatHost;
22
using Microsoft.GS.DPS.Storage.ChatSessions.Entities;
33
using Microsoft.GS.DPS.Storage.ChatSessions;
44
using Microsoft.KernelMemory;
@@ -159,6 +159,7 @@ public async Task<ChatResponse> Chat(ChatRequest chatRequest)
159159
//Get the answer from the Kernel Memory
160160
var answer = await _kernelMemory.Ask(chatRequest.Question + ChatHost.s_additionalPrompt, chatRequest.DocumentIds, context: context);
161161

162+
answer.Result = System.Text.Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(answer.Result));
162163
Console.WriteLine($"Question: {answer.Question}");
163164
Console.WriteLine($"Answer: {answer.Result}");
164165

@@ -201,8 +202,13 @@ public async Task<ChatResponse> Chat(ChatRequest chatRequest)
201202

202203
try
203204
{
204-
answerObject = JsonSerializer.Deserialize<Answer>(returnedChatMessageContent.Content, options: JsonSerializationOptionsCache.JsonSerializationOptionsIgnoreCase);
205-
205+
//Adding for non English Response.
206+
returnedChatMessageContent.Content = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(returnedChatMessageContent.Content));
207+
answerObject = JsonSerializer.Deserialize<Answer>(returnedChatMessageContent.Content, options: new JsonSerializerOptions
208+
{
209+
PropertyNameCaseInsensitive = true,
210+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
211+
});
206212
}
207213
catch
208214
{
@@ -245,4 +251,4 @@ public async Task<ChatResponse> Chat(ChatRequest chatRequest)
245251
};
246252
}
247253
}
248-
}
254+
}

0 commit comments

Comments
 (0)