From bc4c3a517cff0b7ffbc3c6a95b5ad13ebfe25aed Mon Sep 17 00:00:00 2001 From: kavin <115390646+singhk97@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:33:50 -0500 Subject: [PATCH] [C#] fix: failure to load prompt due to json serialization error (#2227) ## Linked issues closes: #minor (issue number) ## Details - Bumping `JsonSchema` to v6.1.2 so that it uses `Json.More.Net` version 2.x - Fixed a test failure in a previous PR (.net build was not run) #### Change details _Exception_ ``` Microsoft.Teams.AI.Exceptions.TeamsAIException: Error while loading prompt. Method not found: \u0027!!0 Json.More.JsonSerializerOptionsExtensions.Read(System.Text.Json.JsonSerializerOptions, System.Text.Json.Utf8JsonReader ByRef)\u0027.\r\n at Microsoft.Teams.AI.AI.Prompts.PromptManager._LoadPromptTemplateFromFile(String name)\r\n at Microsoft.Teams.AI.AI.Prompts.PromptManager.GetPrompt(String name)\r\n at Program.\u003C\u003Ec__DisplayClass0_1.\u003C\u003C\u003CMain\u003E$\u003Eb__14\u003Ed.MoveNext() in C:\\TFS\\Icertis.AI.M365Copilot\\Icertis.AI.M365Copilot.App\\Program.cs:line 148\r\n--- End of stack trace from previous location ---\r\n at Microsoft.Teams.AI.AI.Planners.ActionPlanner\u00601.ContinueTaskAsync(ITurnContext context, TState state, AI\u00601 ai, CancellationToken cancellationToken)\r\n at Microsoft.Teams.AI.AI.Planners.ActionPlanner\u00601.BeginTaskAsync(ITurnContext context, TState state, AI\u00601 ai, CancellationToken cancellationToken)\r\n at Microsoft.Teams.AI.AI.AI\u00601.RunAsync(ITurnContext turnContext, TState turnState, Nullable\u00601 startTime, Int32 stepCount, CancellationToken cancellationToken)\r\n at Microsoft.Teams.AI.Application\u00601._OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)\r\n at Microsoft.Teams.AI.Application\u00601.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)\r\n at Microsoft.Teams.AI.Application.Authentication.Bot.FilteredTeamsSSOTokenExchangeMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)\r\n at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)\r\n at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken) ``` ## Attestation Checklist - [x] My code follows the style guidelines of this project - I have checked for/fixed spelling, linting, and other errors - I have commented my code for clarity - I have made corresponding changes to the documentation (updating the doc strings in the code is sufficient) - My changes generate no new warnings - I have added tests that validates my changes, and provides sufficient test coverage. I have tested with: - Local testing - E2E testing in Teams - New and existing unit tests pass locally with my changes --- .../Microsoft.TeamsAI.Tests/AITests/LLMClientTests.cs | 7 ++++++- .../Microsoft.TeamsAI/Microsoft.Teams.AI.csproj | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/AITests/LLMClientTests.cs b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/AITests/LLMClientTests.cs index 4db309d8f..9278c1477 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/AITests/LLMClientTests.cs +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/AITests/LLMClientTests.cs @@ -99,8 +99,10 @@ public async Task Test_CompletePromptAsync_PromptResponse_NotSuccess() LLMClientOptions options = new(promptCompletionModel, promptTemplate) { MaxHistoryMessages = 1 }; LLMClient client = new(options, null); TestMemory memory = new(); + ChatMessage message = new ChatMessage("Hi there"); promptCompletionModel.Results.Enqueue(new() { + Input = new List() { message }, Status = PromptResponseStatus.Error, Error = new TeamsAIException("test") }); @@ -113,7 +115,10 @@ public async Task Test_CompletePromptAsync_PromptResponse_NotSuccess() Assert.Equal(PromptResponseStatus.Error, response.Status); Assert.NotNull(response.Error); Assert.Equal("test", response.Error.Message); - Assert.Empty(memory.Values); + Assert.Single(memory.Values); + + IList conversation_history = (IList)memory.GetValue("conversation.history")!; + Assert.True(conversation_history[0].Content == message.Content); } [Fact] diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj index 3025fc921..a6e4c34d4 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/Microsoft.Teams.AI.csproj @@ -38,7 +38,7 @@ - +